Remove boxing support from `windows-core` crate (#3131)
This commit is contained in:
Родитель
41d2e997ae
Коммит
dffa8b03dc
|
@ -160,8 +160,6 @@ jobs:
|
||||||
run: cargo clippy -p test_core
|
run: cargo clippy -p test_core
|
||||||
- name: Clippy test_debug
|
- name: Clippy test_debug
|
||||||
run: cargo clippy -p test_debug
|
run: cargo clippy -p test_debug
|
||||||
- name: Clippy test_debug_inspectable
|
|
||||||
run: cargo clippy -p test_debug_inspectable
|
|
||||||
- name: Clippy test_debugger_visualizer
|
- name: Clippy test_debugger_visualizer
|
||||||
run: cargo clippy -p test_debugger_visualizer
|
run: cargo clippy -p test_debugger_visualizer
|
||||||
- name: Clippy test_deprecated
|
- name: Clippy test_deprecated
|
||||||
|
|
|
@ -186,8 +186,6 @@ jobs:
|
||||||
run: cargo test -p test_core --target ${{ matrix.target }} ${{ matrix.etc }}
|
run: cargo test -p test_core --target ${{ matrix.target }} ${{ matrix.etc }}
|
||||||
- name: Test test_debug
|
- name: Test test_debug
|
||||||
run: cargo test -p test_debug --target ${{ matrix.target }} ${{ matrix.etc }}
|
run: cargo test -p test_debug --target ${{ matrix.target }} ${{ matrix.etc }}
|
||||||
- name: Test test_debug_inspectable
|
|
||||||
run: cargo test -p test_debug_inspectable --target ${{ matrix.target }} ${{ matrix.etc }}
|
|
||||||
- name: Test test_debugger_visualizer
|
- name: Test test_debugger_visualizer
|
||||||
run: cargo test -p test_debugger_visualizer --target ${{ matrix.target }} ${{ matrix.etc }}
|
run: cargo test -p test_debugger_visualizer --target ${{ matrix.target }} ${{ matrix.etc }}
|
||||||
- name: Test test_deprecated
|
- name: Test test_deprecated
|
||||||
|
@ -258,10 +256,10 @@ jobs:
|
||||||
run: cargo test -p test_riddle --target ${{ matrix.target }} ${{ matrix.etc }}
|
run: cargo test -p test_riddle --target ${{ matrix.target }} ${{ matrix.etc }}
|
||||||
- name: Test test_standalone
|
- name: Test test_standalone
|
||||||
run: cargo test -p test_standalone --target ${{ matrix.target }} ${{ matrix.etc }}
|
run: cargo test -p test_standalone --target ${{ matrix.target }} ${{ matrix.etc }}
|
||||||
- name: Clean
|
|
||||||
run: cargo clean
|
|
||||||
- name: Test test_string_param
|
- name: Test test_string_param
|
||||||
run: cargo test -p test_string_param --target ${{ matrix.target }} ${{ matrix.etc }}
|
run: cargo test -p test_string_param --target ${{ matrix.target }} ${{ matrix.etc }}
|
||||||
|
- name: Clean
|
||||||
|
run: cargo clean
|
||||||
- name: Test test_strings
|
- name: Test test_strings
|
||||||
run: cargo test -p test_strings --target ${{ matrix.target }} ${{ matrix.etc }}
|
run: cargo test -p test_strings --target ${{ matrix.target }} ${{ matrix.etc }}
|
||||||
- name: Test test_structs
|
- name: Test test_structs
|
||||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -8,7 +8,7 @@ use core::ptr::null_mut;
|
||||||
/// [IInspectable](https://docs.microsoft.com/en-us/windows/win32/api/inspectable/nn-inspectable-iinspectable)
|
/// [IInspectable](https://docs.microsoft.com/en-us/windows/win32/api/inspectable/nn-inspectable-iinspectable)
|
||||||
/// interface.
|
/// interface.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
pub struct IInspectable(pub IUnknown);
|
pub struct IInspectable(pub IUnknown);
|
||||||
|
|
||||||
interface_hierarchy!(IInspectable, IUnknown);
|
interface_hierarchy!(IInspectable, IUnknown);
|
||||||
|
@ -104,82 +104,3 @@ impl IInspectable_Vtbl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Debug for IInspectable {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
||||||
// Attempts to retrieve the string representation of the object via the
|
|
||||||
// IStringable interface. If that fails, it will use the canonical type
|
|
||||||
// name to give some idea of what the object represents.
|
|
||||||
let name = <Self as Interface>::cast::<imp::IStringable>(self)
|
|
||||||
.and_then(|s| s.ToString())
|
|
||||||
.or_else(|_| self.GetRuntimeClassName())
|
|
||||||
.unwrap_or_default();
|
|
||||||
write!(f, "\"{}\"", name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! primitive_boxed_type {
|
|
||||||
($(($t:ty, $m:ident)),+) => {
|
|
||||||
$(impl TryFrom<$t> for IInspectable {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: $t) -> Result<Self> {
|
|
||||||
imp::PropertyValue::$m(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<IInspectable> for $t {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: IInspectable) -> Result<Self> {
|
|
||||||
<IInspectable as Interface>::cast::<imp::IReference<$t>>(&value)?.Value()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<&IInspectable> for $t {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: &IInspectable) -> Result<Self> {
|
|
||||||
<IInspectable as Interface>::cast::<imp::IReference<$t>>(value)?.Value()
|
|
||||||
}
|
|
||||||
})*
|
|
||||||
};
|
|
||||||
}
|
|
||||||
primitive_boxed_type! {
|
|
||||||
(bool, CreateBoolean),
|
|
||||||
(u8, CreateUInt8),
|
|
||||||
(i16, CreateInt16),
|
|
||||||
(u16, CreateUInt16),
|
|
||||||
(i32, CreateInt32),
|
|
||||||
(u32, CreateUInt32),
|
|
||||||
(i64, CreateInt64),
|
|
||||||
(u64, CreateUInt64),
|
|
||||||
(f32, CreateSingle),
|
|
||||||
(f64, CreateDouble)
|
|
||||||
}
|
|
||||||
impl TryFrom<&str> for IInspectable {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: &str) -> Result<Self> {
|
|
||||||
let value: HSTRING = value.into();
|
|
||||||
imp::PropertyValue::CreateString(&value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<HSTRING> for IInspectable {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: HSTRING) -> Result<Self> {
|
|
||||||
imp::PropertyValue::CreateString(&value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<&HSTRING> for IInspectable {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: &HSTRING) -> Result<Self> {
|
|
||||||
imp::PropertyValue::CreateString(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<IInspectable> for HSTRING {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: IInspectable) -> Result<Self> {
|
|
||||||
<IInspectable as Interface>::cast::<imp::IReference<HSTRING>>(&value)?.Value()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<&IInspectable> for HSTRING {
|
|
||||||
type Error = Error;
|
|
||||||
fn try_from(value: &IInspectable) -> Result<Self> {
|
|
||||||
<IInspectable as Interface>::cast::<imp::IReference<HSTRING>>(value)?.Value()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "test_debug_inspectable"
|
|
||||||
version = "0.0.0"
|
|
||||||
edition = "2021"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
doc = false
|
|
||||||
doctest = false
|
|
||||||
|
|
||||||
[dependencies.windows]
|
|
||||||
path = "../../libs/windows"
|
|
||||||
features = [
|
|
||||||
"Foundation_Collections",
|
|
||||||
]
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
use windows::{core::*, Foundation::Collections::*, Foundation::*};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test() -> Result<()> {
|
|
||||||
let stringable: IInspectable = Uri::CreateUri(h!("https://kennykerr.ca"))?.cast()?;
|
|
||||||
let non_stringable: IInspectable = PropertySet::new()?.cast()?;
|
|
||||||
|
|
||||||
assert_eq!(format!("{:?}", stringable), "\"https://kennykerr.ca/\"");
|
|
||||||
assert_eq!(
|
|
||||||
format!("{:?}", non_stringable),
|
|
||||||
"\"Windows.Foundation.Collections.PropertySet\""
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
|
@ -1,121 +0,0 @@
|
||||||
use windows::core::*;
|
|
||||||
use windows::Foundation::*;
|
|
||||||
|
|
||||||
macro_rules! primitive_try_into_test {
|
|
||||||
($(($t:ty, $v:literal)),+) => {
|
|
||||||
$(
|
|
||||||
let o: IInspectable = $v.try_into()?;
|
|
||||||
let t: $t = (&o).try_into()?;
|
|
||||||
assert_eq!($v, t);
|
|
||||||
let t: $t = o.try_into()?;
|
|
||||||
assert_eq!($v, t);
|
|
||||||
)*
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! primitive_try_from_test {
|
|
||||||
($(($t:ty, $v:literal)),+) => {
|
|
||||||
$(
|
|
||||||
let o = IInspectable::try_from($v)?;
|
|
||||||
assert_eq!($v, <$t>::try_from(&o)?);
|
|
||||||
assert_eq!($v, <$t>::try_from(o)?);
|
|
||||||
)*
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn boxing_into() -> Result<()> {
|
|
||||||
primitive_try_into_test! {
|
|
||||||
(bool, true),
|
|
||||||
(bool, false),
|
|
||||||
(u8, 123_u8),
|
|
||||||
(i16, 123_i16),
|
|
||||||
(u16, 123_u16),
|
|
||||||
(i32, 123_i32),
|
|
||||||
(u32, 123_u32),
|
|
||||||
(i64, 123_i64),
|
|
||||||
(u64, 123_u64),
|
|
||||||
(f32, 123_f32),
|
|
||||||
(f64, 123_f64)
|
|
||||||
}
|
|
||||||
|
|
||||||
primitive_try_from_test! {
|
|
||||||
(bool, true),
|
|
||||||
(bool, false),
|
|
||||||
(u8, 123_u8),
|
|
||||||
(i16, 123_i16),
|
|
||||||
(u16, 123_u16),
|
|
||||||
(i32, 123_i32),
|
|
||||||
(u32, 123_u32),
|
|
||||||
(i64, 123_i64),
|
|
||||||
(u64, 123_u64),
|
|
||||||
(f32, 123_f32),
|
|
||||||
(f64, 123_f64)
|
|
||||||
}
|
|
||||||
|
|
||||||
let o: IInspectable = "hello".try_into()?;
|
|
||||||
let v: HSTRING = (&o).try_into()?;
|
|
||||||
assert!("hello" == v);
|
|
||||||
let v: HSTRING = o.try_into()?;
|
|
||||||
assert!("hello" == v);
|
|
||||||
|
|
||||||
let v = HSTRING::from("hello");
|
|
||||||
let o: IInspectable = (&v).try_into()?;
|
|
||||||
let v: HSTRING = (&o).try_into()?;
|
|
||||||
assert!("hello" == v);
|
|
||||||
let v: HSTRING = o.try_into()?;
|
|
||||||
assert!("hello" == v);
|
|
||||||
|
|
||||||
let v = HSTRING::from("hello");
|
|
||||||
let o: IInspectable = v.try_into()?;
|
|
||||||
let v: HSTRING = o.try_into()?;
|
|
||||||
assert!("hello" == v);
|
|
||||||
|
|
||||||
let o = IInspectable::try_from("hello")?;
|
|
||||||
assert_eq!("hello", HSTRING::try_from(&o)?);
|
|
||||||
assert_eq!("hello", HSTRING::try_from(o)?);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn explicit_boxing() -> Result<()> {
|
|
||||||
let object = PropertyValue::CreateString(&HSTRING::from("hello"))?;
|
|
||||||
let pv: IPropertyValue = object.cast()?;
|
|
||||||
assert!(pv.GetString()? == "hello");
|
|
||||||
|
|
||||||
let object = PropertyValue::CreateUInt32Array(&[1, 2, 3])?;
|
|
||||||
let pv: IPropertyValue = object.cast()?;
|
|
||||||
let mut array = Array::new();
|
|
||||||
assert!(array.is_empty());
|
|
||||||
assert!(array.is_empty());
|
|
||||||
|
|
||||||
pv.GetUInt32Array(&mut array)?;
|
|
||||||
assert!(array[..] == [1, 2, 3]);
|
|
||||||
assert!(!array.is_empty());
|
|
||||||
assert!(array.len() == 3);
|
|
||||||
|
|
||||||
let object =
|
|
||||||
PropertyValue::CreateStringArray(&["Hello".into(), "Rust".into(), "WinRT".into()])?;
|
|
||||||
let pv: IPropertyValue = object.cast()?;
|
|
||||||
let mut array = Array::new();
|
|
||||||
assert!(array.is_empty());
|
|
||||||
assert!(array.is_empty());
|
|
||||||
|
|
||||||
pv.GetStringArray(&mut array)?;
|
|
||||||
assert!(array[..] == ["Hello", "Rust", "WinRT"]);
|
|
||||||
assert!(!array.is_empty());
|
|
||||||
assert!(array.len() == 3);
|
|
||||||
array.clear();
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reference_array() -> Result<()> {
|
|
||||||
let object = PropertyValue::CreateInt32Array(&[1, 2, 3])?;
|
|
||||||
let array: IReferenceArray<i32> = object.cast()?;
|
|
||||||
let array: Array<i32> = array.Value()?;
|
|
||||||
assert_eq!(array[..], [1, 2, 3]);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@ use core::convert::*;
|
||||||
use windows::{
|
use windows::{
|
||||||
core::Interface,
|
core::Interface,
|
||||||
Foundation::Collections::{IIterable, IVectorView, PropertySet},
|
Foundation::Collections::{IIterable, IVectorView, PropertySet},
|
||||||
Foundation::{IWwwFormUrlDecoderEntry, Uri},
|
Foundation::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -73,15 +73,15 @@ fn property_set() -> windows::core::Result<()> {
|
||||||
|
|
||||||
set.Insert(
|
set.Insert(
|
||||||
&windows::core::HSTRING::from("A"),
|
&windows::core::HSTRING::from("A"),
|
||||||
&windows::core::IInspectable::try_from(1)?,
|
&PropertyValue::CreateInt32(1)?,
|
||||||
)?;
|
)?;
|
||||||
set.Insert(
|
set.Insert(
|
||||||
&windows::core::HSTRING::from("B"),
|
&windows::core::HSTRING::from("B"),
|
||||||
&windows::core::IInspectable::try_from(2)?,
|
&PropertyValue::CreateInt32(2)?,
|
||||||
)?;
|
)?;
|
||||||
set.Insert(
|
set.Insert(
|
||||||
&windows::core::HSTRING::from("C"),
|
&windows::core::HSTRING::from("C"),
|
||||||
&windows::core::IInspectable::try_from(3)?,
|
&PropertyValue::CreateInt32(3)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
assert!(set.Size()? == 3);
|
assert!(set.Size()? == 3);
|
||||||
|
@ -91,7 +91,7 @@ fn property_set() -> windows::core::Result<()> {
|
||||||
|
|
||||||
for pair in &set {
|
for pair in &set {
|
||||||
keys.push(pair.Key()?.to_string());
|
keys.push(pair.Key()?.to_string());
|
||||||
values += i32::try_from(pair.Value()?)?;
|
values += pair.Value()?.cast::<IReference<i32>>()?.Value()?;
|
||||||
}
|
}
|
||||||
assert!(set.Size()? == 3);
|
assert!(set.Size()? == 3);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
use core::convert::*;
|
use core::convert::*;
|
||||||
|
|
||||||
use windows::{
|
use windows::{Foundation::Collections::*, Foundation::*};
|
||||||
Foundation::Collections::{
|
|
||||||
CollectionChange, IObservableMap, MapChangedEventHandler, PropertySet,
|
|
||||||
},
|
|
||||||
Foundation::{AsyncActionCompletedHandler, AsyncStatus, TypedEventHandler, Uri},
|
|
||||||
};
|
|
||||||
|
|
||||||
use windows::core::Interface;
|
use windows::core::Interface;
|
||||||
|
|
||||||
|
@ -87,7 +82,7 @@ fn event() -> windows::core::Result<()> {
|
||||||
|
|
||||||
set.Insert(
|
set.Insert(
|
||||||
&windows::core::HSTRING::from("A"),
|
&windows::core::HSTRING::from("A"),
|
||||||
&windows::core::IInspectable::try_from(1_u32)?,
|
&PropertyValue::CreateUInt32(1_u32)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
assert!(rx.recv().unwrap());
|
assert!(rx.recv().unwrap());
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
--config flatten minimal no-bindgen-comment
|
--config flatten minimal no-bindgen-comment
|
||||||
|
|
||||||
--filter
|
--filter
|
||||||
Windows.Foundation.IReference
|
|
||||||
Windows.Foundation.IStringable
|
|
||||||
Windows.Foundation.PropertyValue
|
|
||||||
Windows.Win32.Foundation.CO_E_NOTINITIALIZED
|
Windows.Win32.Foundation.CO_E_NOTINITIALIZED
|
||||||
Windows.Win32.Foundation.E_BOUNDS
|
Windows.Win32.Foundation.E_BOUNDS
|
||||||
Windows.Win32.Foundation.E_NOINTERFACE
|
Windows.Win32.Foundation.E_NOINTERFACE
|
||||||
|
|
Загрузка…
Ссылка в новой задаче