String trait refactoring (#2863)
This commit is contained in:
Родитель
075c3c121a
Коммит
65b8ada281
|
@ -79,3 +79,15 @@ where
|
|||
Param::Owned(std::mem::transmute_copy(&self))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoParam<PCWSTR> for &BSTR {
|
||||
unsafe fn into_param(self) -> Param<PCWSTR> {
|
||||
Param::Owned(PCWSTR(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoParam<PCWSTR> for &HSTRING {
|
||||
unsafe fn into_param(self) -> Param<PCWSTR> {
|
||||
Param::Owned(PCWSTR(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,3 +28,7 @@ primitives! {
|
|||
(f32, b"f4"),
|
||||
(f64, b"f8")
|
||||
}
|
||||
|
||||
impl RuntimeType for HSTRING {
|
||||
const SIGNATURE: crate::imp::ConstBuffer = crate::imp::ConstBuffer::from_slice(b"string");
|
||||
}
|
||||
|
|
|
@ -111,12 +111,6 @@ impl TryFrom<BSTR> for String {
|
|||
}
|
||||
}
|
||||
|
||||
impl IntoParam<PCWSTR> for &BSTR {
|
||||
unsafe fn into_param(self) -> Param<PCWSTR> {
|
||||
Param::Owned(PCWSTR(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BSTR {
|
||||
fn default() -> Self {
|
||||
Self(std::ptr::null_mut())
|
||||
|
@ -168,7 +162,3 @@ impl Drop for BSTR {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeKind for BSTR {
|
||||
type TypeKind = ValueType;
|
||||
}
|
||||
|
|
|
@ -87,14 +87,6 @@ impl HSTRING {
|
|||
}
|
||||
}
|
||||
|
||||
impl RuntimeType for HSTRING {
|
||||
const SIGNATURE: crate::imp::ConstBuffer = crate::imp::ConstBuffer::from_slice(b"string");
|
||||
}
|
||||
|
||||
impl TypeKind for HSTRING {
|
||||
type TypeKind = ValueType;
|
||||
}
|
||||
|
||||
impl Default for HSTRING {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
|
@ -397,12 +389,6 @@ impl From<HSTRING> for std::ffi::OsString {
|
|||
}
|
||||
}
|
||||
|
||||
impl IntoParam<PCWSTR> for &HSTRING {
|
||||
unsafe fn into_param(self) -> Param<PCWSTR> {
|
||||
Param::Owned(PCWSTR(self.as_ptr()))
|
||||
}
|
||||
}
|
||||
|
||||
const REFERENCE_FLAG: u32 = 1;
|
||||
|
||||
#[repr(C)]
|
||||
|
|
|
@ -25,8 +25,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
/// An internal helper for decoding an iterator of chars and displaying them
|
||||
#[doc(hidden)]
|
||||
pub struct Decode<F>(pub F);
|
||||
struct Decode<F>(pub F);
|
||||
|
||||
impl<F, R, E> std::fmt::Display for Decode<F>
|
||||
where
|
||||
|
|
|
@ -54,20 +54,3 @@ impl PCSTR {
|
|||
Decode(move || decode_utf8(self.as_bytes()))
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeKind for PCSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn can_display() {
|
||||
// 💖 followed by an invalid byte sequence and then an incomplete one
|
||||
let s = [240, 159, 146, 150, 255, 240, 159, 0];
|
||||
let s = PCSTR::from_raw(s.as_ptr());
|
||||
assert_eq!("💖<EFBFBD>", format!("{}", unsafe { s.display() }));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,3 @@ impl PCWSTR {
|
|||
Decode(move || std::char::decode_utf16(self.as_wide().iter().cloned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeKind for PCWSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,3 @@ impl PSTR {
|
|||
Decode(move || decode_utf8(self.as_bytes()))
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeKind for PSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,3 @@ impl PWSTR {
|
|||
Decode(move || std::char::decode_utf16(self.as_wide().iter().cloned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeKind for PWSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
|
|
@ -98,3 +98,27 @@ primitives!(bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, usize, isize);
|
|||
|
||||
#[doc(hidden)]
|
||||
pub type AbiType<T> = <T as Type<T>>::Abi;
|
||||
|
||||
impl TypeKind for PWSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
||||
impl TypeKind for PSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
||||
impl TypeKind for PCWSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
||||
impl TypeKind for PCSTR {
|
||||
type TypeKind = CopyType;
|
||||
}
|
||||
|
||||
impl TypeKind for HSTRING {
|
||||
type TypeKind = ValueType;
|
||||
}
|
||||
|
||||
impl TypeKind for BSTR {
|
||||
type TypeKind = ValueType;
|
||||
}
|
||||
|
|
|
@ -20,3 +20,11 @@ fn test() -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_display() {
|
||||
// 💖 followed by an invalid byte sequence and then an incomplete one
|
||||
let s = [240, 159, 146, 150, 255, 240, 159, 0];
|
||||
let s = PCSTR::from_raw(s.as_ptr());
|
||||
assert_eq!("💖<EFBFBD>", format!("{}", unsafe { s.display() }));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче