From cc5490d6e7e506e3247906129421895d9b351d01 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 20 Aug 2024 15:31:07 -0500 Subject: [PATCH 1/5] async --- crates/libs/bindgen/src/metadata.rs | 9 - crates/libs/bindgen/src/rust/classes.rs | 57 +++- crates/libs/bindgen/src/rust/interfaces.rs | 8 - crates/libs/bindgen/src/rust/writer.rs | 77 ----- crates/libs/metadata/src/type_name.rs | 1 + .../libs/windows/src/extensions/Foundation.rs | 1 + .../src/extensions/Foundation/Async.rs | 276 ++++++++++++++++++ crates/tests/futures/Cargo.toml | 19 ++ crates/tests/futures/src/lib.rs | 1 + crates/tests/futures/tests/tests.rs | 85 ++++++ 10 files changed, 432 insertions(+), 102 deletions(-) create mode 100644 crates/libs/windows/src/extensions/Foundation/Async.rs create mode 100644 crates/tests/futures/Cargo.toml create mode 100644 crates/tests/futures/src/lib.rs create mode 100644 crates/tests/futures/tests/tests.rs diff --git a/crates/libs/bindgen/src/metadata.rs b/crates/libs/bindgen/src/metadata.rs index af2c387dde..bddacc45ec 100644 --- a/crates/libs/bindgen/src/metadata.rs +++ b/crates/libs/bindgen/src/metadata.rs @@ -60,15 +60,6 @@ pub struct SignatureParam { pub kind: SignatureParamKind, } -#[derive(PartialEq, Eq, Debug)] -pub enum AsyncKind { - None, - Action, - ActionWithProgress, - Operation, - OperationWithProgress, -} - #[derive(Clone, PartialEq, Eq, Default)] pub struct Guid( pub u32, diff --git a/crates/libs/bindgen/src/rust/classes.rs b/crates/libs/bindgen/src/rust/classes.rs index 81e5077fc7..78f8db0f22 100644 --- a/crates/libs/bindgen/src/rust/classes.rs +++ b/crates/libs/bindgen/src/rust/classes.rs @@ -30,6 +30,18 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream { let name = to_ident(def.name()); let interfaces = metadata::type_interfaces(&metadata::Type::TypeDef(def, Vec::new())); + + // If the default interface is one of the async interfaces then we can simply replace it with a type alias + // for the async interface. This simplifies and reduces code gen and but also provides a more streamlined + // developer experience. This works because the default interface is the same vtable as the class itself. + if let Some(interface) = is_default_async(&interfaces) { + let interface_name = writer.type_name(&interface.ty); + + return quote! { + pub type #name = #interface_name; + }; + } + let mut methods = quote! {}; let mut method_names = MethodNames::new(); @@ -132,14 +144,6 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream { true, )); tokens.combine(&writer.runtime_name_trait(def, &[], &name, &TokenStream::new(), &features)); - tokens.combine(&writer.async_get( - def, - &[], - &name, - &TokenStream::new(), - &TokenStream::new(), - &features, - )); tokens.combine(&iterators::writer( writer, def, @@ -241,3 +245,40 @@ fn type_is_exclusive(ty: &metadata::Type) -> bool { _ => false, } } + +fn is_default_async(interfaces: &[metadata::Interface]) -> Option<&metadata::Interface> { + let pos = interfaces.iter().position(|interface| { + if interface.kind == metadata::InterfaceKind::Default { + if let metadata::Type::TypeDef(def, _) = interface.ty { + if matches!( + def.type_name(), + metadata::TypeName::IAsyncAction + | metadata::TypeName::IAsyncActionWithProgress + | metadata::TypeName::IAsyncOperation + | metadata::TypeName::IAsyncOperationWithProgress + ) { + return true; + } + } + } + false + }); + + if let Some(pos) = pos { + if interfaces.len() == 1 { + return interfaces.get(0); + } + + if interfaces.len() == 2 { + let info = if pos == 0 { 1 } else { 0 }; + + if let metadata::Type::TypeDef(def, _) = interfaces[info].ty { + if def.type_name() == metadata::TypeName::IAsyncInfo { + return interfaces.get(pos); + } + } + } + } + + None +} diff --git a/crates/libs/bindgen/src/rust/interfaces.rs b/crates/libs/bindgen/src/rust/interfaces.rs index 6cfa18cab7..3ebabde5dc 100644 --- a/crates/libs/bindgen/src/rust/interfaces.rs +++ b/crates/libs/bindgen/src/rust/interfaces.rs @@ -201,14 +201,6 @@ fn gen_win_interface(writer: &Writer, def: metadata::TypeDef) -> TokenStream { } }); - tokens.combine(&writer.async_get( - def, - generics, - &ident, - &constraints, - &phantoms, - &features, - )); tokens.combine(&iterators::writer( writer, def, diff --git a/crates/libs/bindgen/src/rust/writer.rs b/crates/libs/bindgen/src/rust/writer.rs index 3da4429bcc..c4cf767e8f 100644 --- a/crates/libs/bindgen/src/rust/writer.rs +++ b/crates/libs/bindgen/src/rust/writer.rs @@ -634,72 +634,7 @@ impl Writer { quote! {} } } - pub fn async_get( - &self, - def: metadata::TypeDef, - generics: &[metadata::Type], - ident: &TokenStream, - constraints: &TokenStream, - _phantoms: &TokenStream, - features: &TokenStream, - ) -> TokenStream { - let mut kind = type_def_async_kind(def); - let mut async_generics = generics.to_vec(); - - if kind == metadata::AsyncKind::None { - for interface in def.interface_impls().map(move |imp| imp.ty(generics)) { - if let metadata::Type::TypeDef(interface_def, interface_generics) = &interface { - kind = type_def_async_kind(*interface_def); - if kind != metadata::AsyncKind::None { - async_generics = interface_generics.to_vec(); - break; - } - } - } - } - - if kind == metadata::AsyncKind::None { - quote! {} - } else { - let return_type = match kind { - metadata::AsyncKind::Operation | metadata::AsyncKind::OperationWithProgress => { - self.type_name(&async_generics[0]) - } - _ => quote! { () }, - }; - let handler = match kind { - metadata::AsyncKind::Action => quote! { AsyncActionCompletedHandler }, - metadata::AsyncKind::ActionWithProgress => { - quote! { AsyncActionWithProgressCompletedHandler } - } - metadata::AsyncKind::Operation => quote! { AsyncOperationCompletedHandler }, - metadata::AsyncKind::OperationWithProgress => { - quote! { AsyncOperationWithProgressCompletedHandler } - } - rest => unimplemented!("{rest:?}"), - }; - - let namespace = self.namespace("Windows.Foundation"); - - quote! { - #features - impl<#constraints> #ident { - pub fn get(&self) -> windows_core::Result<#return_type> { - if self.Status()? == #namespace AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&#namespace #handler::new(move |_sender, _args| { - // Safe because the waiter will only be dropped after being signaled. - unsafe { signaler.signal(); } - Ok(()) - }))?; - } - self.GetResults() - } - } - } - } - } pub fn interface_winrt_trait( &self, def: metadata::TypeDef, @@ -1463,18 +1398,6 @@ fn gen_const_ptrs(pointers: usize) -> TokenStream { "*const ".repeat(pointers).into() } -fn type_def_async_kind(row: metadata::TypeDef) -> metadata::AsyncKind { - match row.type_name() { - metadata::TypeName::IAsyncAction => metadata::AsyncKind::Action, - metadata::TypeName::IAsyncActionWithProgress => metadata::AsyncKind::ActionWithProgress, - metadata::TypeName::IAsyncOperation => metadata::AsyncKind::Operation, - metadata::TypeName::IAsyncOperationWithProgress => { - metadata::AsyncKind::OperationWithProgress - } - _ => metadata::AsyncKind::None, - } -} - fn type_def_is_agile(row: metadata::TypeDef) -> bool { for attribute in row.attributes() { match attribute.name() { diff --git a/crates/libs/metadata/src/type_name.rs b/crates/libs/metadata/src/type_name.rs index 19160a7ad6..e90e083495 100644 --- a/crates/libs/metadata/src/type_name.rs +++ b/crates/libs/metadata/src/type_name.rs @@ -15,6 +15,7 @@ impl TypeName { pub const HResult: Self = Self("Windows.Foundation", "HResult"); pub const IAsyncAction: Self = Self("Windows.Foundation", "IAsyncAction"); + pub const IAsyncInfo: Self = Self("Windows.Foundation", "IAsyncInfo"); pub const IAsyncActionWithProgress: Self = Self("Windows.Foundation", "IAsyncActionWithProgress"); pub const IAsyncOperation: Self = Self("Windows.Foundation", "IAsyncOperation"); diff --git a/crates/libs/windows/src/extensions/Foundation.rs b/crates/libs/windows/src/extensions/Foundation.rs index ea4bfd24ee..95fc7bca6e 100644 --- a/crates/libs/windows/src/extensions/Foundation.rs +++ b/crates/libs/windows/src/extensions/Foundation.rs @@ -1,3 +1,4 @@ +pub mod Async; #[cfg(feature = "Foundation_Collections")] pub mod Collections; #[cfg(feature = "Foundation_Numerics")] diff --git a/crates/libs/windows/src/extensions/Foundation/Async.rs b/crates/libs/windows/src/extensions/Foundation/Async.rs new file mode 100644 index 0000000000..b4f53e3837 --- /dev/null +++ b/crates/libs/windows/src/extensions/Foundation/Async.rs @@ -0,0 +1,276 @@ +use crate::core::{imp::Waiter, Interface, Result, RuntimeType}; +use crate::Foundation::{AsyncActionCompletedHandler, AsyncActionWithProgressCompletedHandler, AsyncOperationCompletedHandler, AsyncOperationWithProgressCompletedHandler}; +use crate::Foundation::{AsyncStatus, IAsyncAction, IAsyncActionWithProgress, IAsyncInfo, IAsyncOperation, IAsyncOperationWithProgress}; +use std::future::{Future, IntoFuture}; +use std::pin::Pin; +use std::sync::{Arc, Mutex}; +use std::task::{Context, Poll, Waker}; + +// An `Async` represents a WinRT async execution object or type. There are precisely four such types: +// - IAsyncAction +// - IAsyncActionWithProgress +// - IAsyncOperation +// - IAsyncOperationWithProgress +// +// All four implementations are provided here and there is thus no need to implement this trait. +// This trait provides an abstraction over the relevant differences so that the `AsyncFuture` +// implementation below can be reused for all of them. +pub trait Async: Interface { + // The type of value produced on completion. + type Output; + + // Sets the handler or callback to invoke when execution completes. This handler can only be set once. + fn set_completed(&self, handler: F) -> Result<()>; + + // Returns the value produced on completion. This should only be called when execution completes. + fn get_results(&self) -> Result; +} + +// The `AsyncFuture` is needed to store some extra state needed to keep async execution up to date with possible changes to Rust execution context. +// Each async type implements `IntoFuture` rather than implementing `Future` directly so that this adapter may be used. +pub struct AsyncFuture { + // Represents the async execution and provides the virtual methods for setting up a `Completed` handler and + // calling `GetResults` when execution is completed. + inner: A, + + // Provides the `Status` virtual method and saves repeated calls to `QueryInterface` during polling. + status: IAsyncInfo, + + // A shared waker is needed to keep the `Completed` handler updated. + // - `Option` is used to avoid allocations for async objects that have already completed. + // - `Arc` is used to share the `Waker` with the `Completed` handler and and potentially replace the `Waker` + // since we don't have the ability to replace the `Completed` handler itself. + // - `Mutex` is used to synchronize replacing the `Waker` across threads. + waker: Option>>, +} + +impl AsyncFuture { + fn new(inner: A) -> Self { + Self { + // All four async interfaces implement `IAsyncInfo` so this `cast` will always succeed. + status: inner.cast().unwrap(), + inner, + waker: None, + } + } +} + +unsafe impl Send for AsyncFuture {} +unsafe impl Sync for AsyncFuture {} +impl Unpin for AsyncFuture {} + +impl Future for AsyncFuture { + type Output = Result; + + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + println!("poll {cx:?}"); + + // A status of `Started` just means async execution is still in flight. Since WinRT async is always + // "hot start", if its not `Started` then its ready for us to call `GetResults` so we can skip all of + // the remaining set up. + if self.status.Status()? != AsyncStatus::Started { + return Poll::Ready(self.inner.get_results()); + } + + if let Some(shared_waker) = &self.waker { + // We have a shared waker which means we're either getting polled again or been transfered to + // another another execution context. Either way, we need to update the shared waker to make sure + // we've got the "current" waker. + let mut guard = shared_waker.lock().unwrap(); + guard.clone_from(cx.waker()); + + // It may be possible that the `Completed` handler acquired the lock and signaled the old waker + // before we managed to acquire the lock to update it with the current waker. We check the status + // again here just in case this happens. + if self.status.Status()? != AsyncStatus::Started { + return Poll::Ready(self.inner.get_results()); + } + } else { + // If we don't have a saved waker it means this is the first time we're getting polled and should + // create the shared waker and set up a `Completed` handler. + let shared_waker = Arc::new(Mutex::new(cx.waker().clone())); + self.waker = Some(shared_waker.clone()); + + // Note that the handler can only be set once, which is why we need a shared waker in the first + // place. On the other hand, the handler will get called even if async execution has already + // completed, so we can just return `Pending` after setting the Completed handler. + self.inner.set_completed(move || { + shared_waker.lock().unwrap().wake_by_ref(); + })?; + }; + + Poll::Pending + } +} + +// +// The four `Async` trait implementations. +// + +impl Async for IAsyncAction { + type Output = (); + + fn set_completed(&self, handler: F) -> Result<()> { + self.SetCompleted(&AsyncActionCompletedHandler::new(move |_, _| { + handler(); + Ok(()) + })) + } + + fn get_results(&self) -> Result { + self.GetResults() + } +} + +impl Async for IAsyncOperation { + type Output = T; + + fn set_completed(&self, handler: F) -> Result<()> { + self.SetCompleted(&AsyncOperationCompletedHandler::new(move |_, _| { + handler(); + Ok(()) + })) + } + + fn get_results(&self) -> Result { + self.GetResults() + } +} + +impl Async for IAsyncActionWithProgress

{ + type Output = (); + + fn set_completed(&self, handler: F) -> Result<()> { + self.SetCompleted(&AsyncActionWithProgressCompletedHandler::new(move |_, _| { + handler(); + Ok(()) + })) + } + + fn get_results(&self) -> Result { + self.GetResults() + } +} + +impl Async for IAsyncOperationWithProgress { + type Output = T; + + fn set_completed(&self, handler: F) -> Result<()> { + self.SetCompleted(&AsyncOperationWithProgressCompletedHandler::new(move |_, _| { + handler(); + Ok(()) + })) + } + + fn get_results(&self) -> Result { + self.GetResults() + } +} + +// +// The four `IntoFuture` trait implementations. +// + +impl IntoFuture for IAsyncAction { + type Output = Result<()>; + type IntoFuture = AsyncFuture; + + fn into_future(self) -> Self::IntoFuture { + AsyncFuture::new(self) + } +} + +impl IntoFuture for IAsyncOperation { + type Output = Result; + type IntoFuture = AsyncFuture; + + fn into_future(self) -> Self::IntoFuture { + AsyncFuture::new(self) + } +} + +impl IntoFuture for IAsyncActionWithProgress

{ + type Output = Result<()>; + type IntoFuture = AsyncFuture; + + fn into_future(self) -> Self::IntoFuture { + AsyncFuture::new(self) + } +} + +impl IntoFuture for IAsyncOperationWithProgress { + type Output = Result; + type IntoFuture = AsyncFuture; + + fn into_future(self) -> Self::IntoFuture { + AsyncFuture::new(self) + } +} + +// +// The four `get` implementations for synchronous completion. +// + +impl IAsyncAction { + pub fn get(&self) -> Result<()> { + if self.Status()? == AsyncStatus::Started { + let (_waiter, signaler) = Waiter::new()?; + self.SetCompleted(&AsyncActionCompletedHandler::new(move |_, _| { + // This is safe because the waiter will only be dropped after being signaled. + unsafe { + signaler.signal(); + } + Ok(()) + }))?; + } + self.GetResults() + } +} + +impl IAsyncOperation { + pub fn get(&self) -> Result { + if self.Status()? == AsyncStatus::Started { + let (_waiter, signaler) = Waiter::new()?; + self.SetCompleted(&AsyncOperationCompletedHandler::new(move |_, _| { + // This is safe because the waiter will only be dropped after being signaled. + unsafe { + signaler.signal(); + } + Ok(()) + }))?; + } + self.GetResults() + } +} + +impl IAsyncActionWithProgress

{ + pub fn get(&self) -> Result<()> { + if self.Status()? == AsyncStatus::Started { + let (_waiter, signaler) = Waiter::new()?; + self.SetCompleted(&AsyncActionWithProgressCompletedHandler::new(move |_, _| { + // This is safe because the waiter will only be dropped after being signaled. + unsafe { + signaler.signal(); + } + Ok(()) + }))?; + } + self.GetResults() + } +} + +impl IAsyncOperationWithProgress { + pub fn get(&self) -> Result { + if self.Status()? == AsyncStatus::Started { + let (_waiter, signaler) = Waiter::new()?; + self.SetCompleted(&AsyncOperationWithProgressCompletedHandler::new(move |_, _| { + // This is safe because the waiter will only be dropped after being signaled. + unsafe { + signaler.signal(); + } + Ok(()) + }))?; + } + self.GetResults() + } +} diff --git a/crates/tests/futures/Cargo.toml b/crates/tests/futures/Cargo.toml new file mode 100644 index 0000000000..e4e456f770 --- /dev/null +++ b/crates/tests/futures/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "test_futures" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +doc = false +doctest = false + +[dependencies.windows] +path = "../../libs/windows" +features = [ + "System_Threading", + "Storage_Streams", +] + +[dev-dependencies] +futures = "0.3" diff --git a/crates/tests/futures/src/lib.rs b/crates/tests/futures/src/lib.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/crates/tests/futures/src/lib.rs @@ -0,0 +1 @@ + diff --git a/crates/tests/futures/tests/tests.rs b/crates/tests/futures/tests/tests.rs new file mode 100644 index 0000000000..9e08bde7fb --- /dev/null +++ b/crates/tests/futures/tests/tests.rs @@ -0,0 +1,85 @@ +use windows::{core::*, Storage::Streams::*, System::Threading::*}; + +// A simple example of blocking synchronously with the `get` method. +#[test] +fn simple_sync() -> Result<()> { + ThreadPool::RunAsync(&WorkItemHandler::new(|_| Ok(())))?.get() +} + +// A simple example of awaiting with an async function. +#[test] +fn simple_async() -> Result<()> { + futures::executor::block_on(async { + ThreadPool::RunAsync(&WorkItemHandler::new(|_| Ok(())))?.await + }) +} + +// A representative example of a WinRT async API. +#[test] +fn stream_async() -> Result<()> { + futures::executor::block_on(async { + let stream = &InMemoryRandomAccessStream::new()?; + + let writer = DataWriter::CreateDataWriter(stream)?; + writer.WriteByte(1)?; + writer.WriteByte(2)?; + writer.WriteByte(3)?; + writer.StoreAsync()?.await?; + + stream.Seek(0)?; + let reader = DataReader::CreateDataReader(stream)?; + reader.LoadAsync(3)?.await?; + + let mut bytes: [u8; 3] = [0; 3]; + reader.ReadBytes(&mut bytes)?; + + assert!(bytes[0] == 1); + assert!(bytes[1] == 2); + assert!(bytes[2] == 3); + + Ok(()) + }) +} + +#[test] +fn switch_context() -> Result<()> { + use futures::{executor::LocalPool, future, task::SpawnExt}; + use std::future::IntoFuture; + + let mut pool = LocalPool::new(); + let (sender, receiver) = std::sync::mpsc::channel::<()>(); + + let async_future = ThreadPool::RunAsync(&WorkItemHandler::new(move |_| { + receiver.recv().unwrap(); + Ok(()) + }))? + .into_future(); + + let select = pool + .spawner() + .spawn_with_handle(async move { + // Poll the future on a given context + match future::select(async_future, future::ready(())).await { + future::Either::Left(_) => panic!("async_future should be blocked"), + future::Either::Right(((), future)) => future, + } + }) + .unwrap(); + + let async_future = pool.run_until(select); + + pool.spawner() + .spawn(async move { + // Poll the future on a different context + let (result, ()) = future::join(async_future, async { + sender.send(()).unwrap(); + }) + .await; + result.unwrap(); + }) + .unwrap(); + + pool.run(); + + Ok(()) +} \ No newline at end of file From 8bf662bea35663863f4898a92e16256f09242e19 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 20 Aug 2024 18:19:57 -0500 Subject: [PATCH 2/5] code gen --- crates/libs/bindgen/src/rust/classes.rs | 6 +- .../windows/src/Windows/Devices/Sms/mod.rs | 544 +----------------- .../windows/src/Windows/Foundation/mod.rs | 56 -- .../Security/Authentication/OnlineId/mod.rs | 165 +----- .../src/Windows/Storage/Streams/mod.rs | 168 +----- 5 files changed, 13 insertions(+), 926 deletions(-) diff --git a/crates/libs/bindgen/src/rust/classes.rs b/crates/libs/bindgen/src/rust/classes.rs index cfa8b1401a..a809775b80 100644 --- a/crates/libs/bindgen/src/rust/classes.rs +++ b/crates/libs/bindgen/src/rust/classes.rs @@ -29,6 +29,8 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream { } let name = to_ident(def.name()); + let cfg = cfg::type_def_cfg(writer, def, &[]); + let features = writer.cfg_features(&cfg); let interfaces = metadata::type_interfaces(&metadata::Type::TypeDef(def, Vec::new())); // If the default interface is one of the async interfaces then we can simply replace it with a type alias @@ -38,6 +40,7 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream { let interface_name = writer.type_name(&interface.ty); return quote! { + #features pub type #name = #interface_name; }; } @@ -45,9 +48,6 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream { let mut methods = quote! {}; let mut method_names = MethodNames::new(); - let cfg = cfg::type_def_cfg(writer, def, &[]); - let features = writer.cfg_features(&cfg); - for interface in &interfaces { if let metadata::Type::TypeDef(def, generics) = &interface.ty { let mut virtual_names = MethodNames::new(); diff --git a/crates/libs/windows/src/Windows/Devices/Sms/mod.rs b/crates/libs/windows/src/Windows/Devices/Sms/mod.rs index bf5fac5377..d9bce3ef06 100644 --- a/crates/libs/windows/src/Windows/Devices/Sms/mod.rs +++ b/crates/libs/windows/src/Windows/Devices/Sms/mod.rs @@ -950,549 +950,17 @@ pub struct ISmsWapMessage_Vtbl { Headers: usize, } #[cfg(feature = "deprecated")] -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct DeleteSmsMessageOperation(windows_core::IUnknown); -#[cfg(feature = "deprecated")] -windows_core::imp::interface_hierarchy!(DeleteSmsMessageOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncAction); -#[cfg(feature = "deprecated")] -windows_core::imp::required_hierarchy!(DeleteSmsMessageOperation, super::super::Foundation::IAsyncInfo); -#[cfg(feature = "deprecated")] -impl DeleteSmsMessageOperation { - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result<()> { - let this = self; - unsafe { (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeType for DeleteSmsMessageOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::(); -} -#[cfg(feature = "deprecated")] -unsafe impl windows_core::Interface for DeleteSmsMessageOperation { - type Vtable = super::super::Foundation::IAsyncAction_Vtbl; - const IID: windows_core::GUID = ::IID; -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeName for DeleteSmsMessageOperation { - const NAME: &'static str = "Windows.Devices.Sms.DeleteSmsMessageOperation"; -} -#[cfg(feature = "deprecated")] -impl DeleteSmsMessageOperation { - pub fn get(&self) -> windows_core::Result<()> { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -#[cfg(feature = "deprecated")] -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct DeleteSmsMessagesOperation(windows_core::IUnknown); -#[cfg(feature = "deprecated")] -windows_core::imp::interface_hierarchy!(DeleteSmsMessagesOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncAction); -#[cfg(feature = "deprecated")] -windows_core::imp::required_hierarchy!(DeleteSmsMessagesOperation, super::super::Foundation::IAsyncInfo); -#[cfg(feature = "deprecated")] -impl DeleteSmsMessagesOperation { - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result<()> { - let this = self; - unsafe { (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeType for DeleteSmsMessagesOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::(); -} -#[cfg(feature = "deprecated")] -unsafe impl windows_core::Interface for DeleteSmsMessagesOperation { - type Vtable = super::super::Foundation::IAsyncAction_Vtbl; - const IID: windows_core::GUID = ::IID; -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeName for DeleteSmsMessagesOperation { - const NAME: &'static str = "Windows.Devices.Sms.DeleteSmsMessagesOperation"; -} -#[cfg(feature = "deprecated")] -impl DeleteSmsMessagesOperation { - pub fn get(&self) -> windows_core::Result<()> { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -#[cfg(feature = "deprecated")] -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct GetSmsDeviceOperation(windows_core::IUnknown); -#[cfg(feature = "deprecated")] -windows_core::imp::interface_hierarchy!(GetSmsDeviceOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncOperation::); -#[cfg(feature = "deprecated")] -windows_core::imp::required_hierarchy!(GetSmsDeviceOperation, super::super::Foundation::IAsyncInfo); -#[cfg(feature = "deprecated")] -impl GetSmsDeviceOperation { - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param>, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeType for GetSmsDeviceOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::>(); -} -#[cfg(feature = "deprecated")] -unsafe impl windows_core::Interface for GetSmsDeviceOperation { - type Vtable = super::super::Foundation::IAsyncOperation_Vtbl; - const IID: windows_core::GUID = as windows_core::Interface>::IID; -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeName for GetSmsDeviceOperation { - const NAME: &'static str = "Windows.Devices.Sms.GetSmsDeviceOperation"; -} -#[cfg(feature = "deprecated")] -impl GetSmsDeviceOperation { - pub fn get(&self) -> windows_core::Result { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -#[cfg(feature = "deprecated")] -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct GetSmsMessageOperation(windows_core::IUnknown); +pub type DeleteSmsMessageOperation = super::super::Foundation::IAsyncAction; #[cfg(feature = "deprecated")] -windows_core::imp::interface_hierarchy!(GetSmsMessageOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncOperation::); +pub type DeleteSmsMessagesOperation = super::super::Foundation::IAsyncAction; #[cfg(feature = "deprecated")] -windows_core::imp::required_hierarchy!(GetSmsMessageOperation, super::super::Foundation::IAsyncInfo); +pub type GetSmsDeviceOperation = super::super::Foundation::IAsyncOperation; #[cfg(feature = "deprecated")] -impl GetSmsMessageOperation { - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param>, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeType for GetSmsMessageOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::>(); -} -#[cfg(feature = "deprecated")] -unsafe impl windows_core::Interface for GetSmsMessageOperation { - type Vtable = super::super::Foundation::IAsyncOperation_Vtbl; - const IID: windows_core::GUID = as windows_core::Interface>::IID; -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeName for GetSmsMessageOperation { - const NAME: &'static str = "Windows.Devices.Sms.GetSmsMessageOperation"; -} -#[cfg(feature = "deprecated")] -impl GetSmsMessageOperation { - pub fn get(&self) -> windows_core::Result { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct GetSmsMessagesOperation(windows_core::IUnknown); +pub type GetSmsMessageOperation = super::super::Foundation::IAsyncOperation; #[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -windows_core::imp::interface_hierarchy!(GetSmsMessagesOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncOperationWithProgress::, i32>); -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -windows_core::imp::required_hierarchy!(GetSmsMessagesOperation, super::super::Foundation::IAsyncInfo); -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -impl GetSmsMessagesOperation { - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } - #[cfg(feature = "Foundation_Collections")] - pub fn SetProgress(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param, i32>>, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetProgress)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - #[cfg(feature = "Foundation_Collections")] - pub fn Progress(&self) -> windows_core::Result, i32>> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Progress)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - #[cfg(feature = "Foundation_Collections")] - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param, i32>>, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - #[cfg(feature = "Foundation_Collections")] - pub fn Completed(&self) -> windows_core::Result, i32>> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - #[cfg(feature = "Foundation_Collections")] - pub fn GetResults(&self) -> windows_core::Result> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } -} -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -impl windows_core::RuntimeType for GetSmsMessagesOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::, i32>>(); -} -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -unsafe impl windows_core::Interface for GetSmsMessagesOperation { - type Vtable = super::super::Foundation::IAsyncOperationWithProgress_Vtbl, i32>; - const IID: windows_core::GUID = , i32> as windows_core::Interface>::IID; -} -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -impl windows_core::RuntimeName for GetSmsMessagesOperation { - const NAME: &'static str = "Windows.Devices.Sms.GetSmsMessagesOperation"; -} -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -impl GetSmsMessagesOperation { - pub fn get(&self) -> windows_core::Result> { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncOperationWithProgressCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} +pub type GetSmsMessagesOperation = super::super::Foundation::IAsyncOperationWithProgress, i32>; #[cfg(feature = "deprecated")] -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct SendSmsMessageOperation(windows_core::IUnknown); -#[cfg(feature = "deprecated")] -windows_core::imp::interface_hierarchy!(SendSmsMessageOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncAction); -#[cfg(feature = "deprecated")] -windows_core::imp::required_hierarchy!(SendSmsMessageOperation, super::super::Foundation::IAsyncInfo); -#[cfg(feature = "deprecated")] -impl SendSmsMessageOperation { - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result<()> { - let this = self; - unsafe { (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeType for SendSmsMessageOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::(); -} -#[cfg(feature = "deprecated")] -unsafe impl windows_core::Interface for SendSmsMessageOperation { - type Vtable = super::super::Foundation::IAsyncAction_Vtbl; - const IID: windows_core::GUID = ::IID; -} -#[cfg(feature = "deprecated")] -impl windows_core::RuntimeName for SendSmsMessageOperation { - const NAME: &'static str = "Windows.Devices.Sms.SendSmsMessageOperation"; -} -#[cfg(feature = "deprecated")] -impl SendSmsMessageOperation { - pub fn get(&self) -> windows_core::Result<()> { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} +pub type SendSmsMessageOperation = super::super::Foundation::IAsyncAction; #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] pub struct SmsAppMessage(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Foundation/mod.rs b/crates/libs/windows/src/Windows/Foundation/mod.rs index 4a7fb315b5..7661062d09 100644 --- a/crates/libs/windows/src/Windows/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/mod.rs @@ -64,20 +64,6 @@ impl IAsyncAction { unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } } } -impl IAsyncAction { - pub fn get(&self) -> windows_core::Result<()> { - if self.Status()? == AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&AsyncActionCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} unsafe impl Send for IAsyncAction {} unsafe impl Sync for IAsyncAction {} impl windows_core::RuntimeType for IAsyncAction { @@ -169,20 +155,6 @@ impl IAsyncActionWithProgress IAsyncActionWithProgress { - pub fn get(&self) -> windows_core::Result<()> { - if self.Status()? == AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&AsyncActionWithProgressCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} unsafe impl Send for IAsyncActionWithProgress {} unsafe impl Sync for IAsyncActionWithProgress {} impl windows_core::RuntimeType for IAsyncActionWithProgress { @@ -324,20 +296,6 @@ impl IAsyncOperation { unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } } } -impl IAsyncOperation { - pub fn get(&self) -> windows_core::Result { - if self.Status()? == AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&AsyncOperationCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} unsafe impl Send for IAsyncOperation {} unsafe impl Sync for IAsyncOperation {} impl windows_core::RuntimeType for IAsyncOperation { @@ -441,20 +399,6 @@ impl IAsyncOperationWithProgress { - pub fn get(&self) -> windows_core::Result { - if self.Status()? == AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&AsyncOperationWithProgressCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} unsafe impl Send for IAsyncOperationWithProgress {} unsafe impl Sync for IAsyncOperationWithProgress {} impl windows_core::RuntimeType for IAsyncOperationWithProgress { diff --git a/crates/libs/windows/src/Windows/Security/Authentication/OnlineId/mod.rs b/crates/libs/windows/src/Windows/Security/Authentication/OnlineId/mod.rs index c7a8c19428..d1cee897ff 100644 --- a/crates/libs/windows/src/Windows/Security/Authentication/OnlineId/mod.rs +++ b/crates/libs/windows/src/Windows/Security/Authentication/OnlineId/mod.rs @@ -426,169 +426,8 @@ impl windows_core::RuntimeName for OnlineIdSystemTicketResult { } unsafe impl Send for OnlineIdSystemTicketResult {} unsafe impl Sync for OnlineIdSystemTicketResult {} -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct SignOutUserOperation(windows_core::IUnknown); -windows_core::imp::interface_hierarchy!(SignOutUserOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::super::Foundation::IAsyncAction); -windows_core::imp::required_hierarchy!(SignOutUserOperation, super::super::super::Foundation::IAsyncInfo); -impl SignOutUserOperation { - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result<()> { - let this = self; - unsafe { (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } -} -impl windows_core::RuntimeType for SignOutUserOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::(); -} -unsafe impl windows_core::Interface for SignOutUserOperation { - type Vtable = super::super::super::Foundation::IAsyncAction_Vtbl; - const IID: windows_core::GUID = ::IID; -} -impl windows_core::RuntimeName for SignOutUserOperation { - const NAME: &'static str = "Windows.Security.Authentication.OnlineId.SignOutUserOperation"; -} -impl SignOutUserOperation { - pub fn get(&self) -> windows_core::Result<()> { - if self.Status()? == super::super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -unsafe impl Send for SignOutUserOperation {} -unsafe impl Sync for SignOutUserOperation {} -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct UserAuthenticationOperation(windows_core::IUnknown); -windows_core::imp::interface_hierarchy!(UserAuthenticationOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::super::Foundation::IAsyncOperation::); -windows_core::imp::required_hierarchy!(UserAuthenticationOperation, super::super::super::Foundation::IAsyncInfo); -impl UserAuthenticationOperation { - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param>, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } -} -impl windows_core::RuntimeType for UserAuthenticationOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::>(); -} -unsafe impl windows_core::Interface for UserAuthenticationOperation { - type Vtable = super::super::super::Foundation::IAsyncOperation_Vtbl; - const IID: windows_core::GUID = as windows_core::Interface>::IID; -} -impl windows_core::RuntimeName for UserAuthenticationOperation { - const NAME: &'static str = "Windows.Security.Authentication.OnlineId.UserAuthenticationOperation"; -} -impl UserAuthenticationOperation { - pub fn get(&self) -> windows_core::Result { - if self.Status()? == super::super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -unsafe impl Send for UserAuthenticationOperation {} -unsafe impl Sync for UserAuthenticationOperation {} +pub type SignOutUserOperation = super::super::super::Foundation::IAsyncAction; +pub type UserAuthenticationOperation = super::super::super::Foundation::IAsyncOperation; #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] pub struct UserIdentity(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Storage/Streams/mod.rs b/crates/libs/windows/src/Windows/Storage/Streams/mod.rs index c2c0712834..0784a50a14 100644 --- a/crates/libs/windows/src/Windows/Storage/Streams/mod.rs +++ b/crates/libs/windows/src/Windows/Storage/Streams/mod.rs @@ -1243,89 +1243,7 @@ impl windows_core::RuntimeName for DataReader { } unsafe impl Send for DataReader {} unsafe impl Sync for DataReader {} -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct DataReaderLoadOperation(windows_core::IUnknown); -windows_core::imp::interface_hierarchy!(DataReaderLoadOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncOperation::); -windows_core::imp::required_hierarchy!(DataReaderLoadOperation, super::super::Foundation::IAsyncInfo); -impl DataReaderLoadOperation { - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param>, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } -} -impl windows_core::RuntimeType for DataReaderLoadOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::>(); -} -unsafe impl windows_core::Interface for DataReaderLoadOperation { - type Vtable = super::super::Foundation::IAsyncOperation_Vtbl; - const IID: windows_core::GUID = as windows_core::Interface>::IID; -} -impl windows_core::RuntimeName for DataReaderLoadOperation { - const NAME: &'static str = "Windows.Storage.Streams.DataReaderLoadOperation"; -} -impl DataReaderLoadOperation { - pub fn get(&self) -> windows_core::Result { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -unsafe impl Send for DataReaderLoadOperation {} -unsafe impl Sync for DataReaderLoadOperation {} +pub type DataReaderLoadOperation = super::super::Foundation::IAsyncOperation; #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] pub struct DataWriter(windows_core::IUnknown); @@ -1511,89 +1429,7 @@ impl windows_core::RuntimeName for DataWriter { } unsafe impl Send for DataWriter {} unsafe impl Sync for DataWriter {} -#[repr(transparent)] -#[derive(PartialEq, Eq, Debug, Clone)] -pub struct DataWriterStoreOperation(windows_core::IUnknown); -windows_core::imp::interface_hierarchy!(DataWriterStoreOperation, windows_core::IUnknown, windows_core::IInspectable, super::super::Foundation::IAsyncOperation::); -windows_core::imp::required_hierarchy!(DataWriterStoreOperation, super::super::Foundation::IAsyncInfo); -impl DataWriterStoreOperation { - pub fn Id(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Id)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Status(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Status)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn ErrorCode(&self) -> windows_core::Result { - let this = &windows_core::Interface::cast::(self)?; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).ErrorCode)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } - pub fn Cancel(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Cancel)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn Close(&self) -> windows_core::Result<()> { - let this = &windows_core::Interface::cast::(self)?; - unsafe { (windows_core::Interface::vtable(this).Close)(windows_core::Interface::as_raw(this)).ok() } - } - pub fn SetCompleted(&self, handler: P0) -> windows_core::Result<()> - where - P0: windows_core::Param>, - { - let this = self; - unsafe { (windows_core::Interface::vtable(this).SetCompleted)(windows_core::Interface::as_raw(this), handler.param().abi()).ok() } - } - pub fn Completed(&self) -> windows_core::Result> { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).Completed)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__)) - } - } - pub fn GetResults(&self) -> windows_core::Result { - let this = self; - unsafe { - let mut result__ = core::mem::zeroed(); - (windows_core::Interface::vtable(this).GetResults)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__) - } - } -} -impl windows_core::RuntimeType for DataWriterStoreOperation { - const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_class::>(); -} -unsafe impl windows_core::Interface for DataWriterStoreOperation { - type Vtable = super::super::Foundation::IAsyncOperation_Vtbl; - const IID: windows_core::GUID = as windows_core::Interface>::IID; -} -impl windows_core::RuntimeName for DataWriterStoreOperation { - const NAME: &'static str = "Windows.Storage.Streams.DataWriterStoreOperation"; -} -impl DataWriterStoreOperation { - pub fn get(&self) -> windows_core::Result { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let (_waiter, signaler) = windows_core::imp::Waiter::new()?; - self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - unsafe { - signaler.signal(); - } - Ok(()) - }))?; - } - self.GetResults() - } -} -unsafe impl Send for DataWriterStoreOperation {} -unsafe impl Sync for DataWriterStoreOperation {} +pub type DataWriterStoreOperation = super::super::Foundation::IAsyncOperation; #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] pub struct FileInputStream(windows_core::IUnknown); From bffe238b16604e0810c22ec1ac70010fe752f873 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 20 Aug 2024 18:33:24 -0500 Subject: [PATCH 3/5] simpler --- crates/libs/bindgen/src/rust/classes.rs | 22 ++-------------------- crates/tests/futures/tests/tests.rs | 8 ++++---- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/crates/libs/bindgen/src/rust/classes.rs b/crates/libs/bindgen/src/rust/classes.rs index a809775b80..9d170bdd03 100644 --- a/crates/libs/bindgen/src/rust/classes.rs +++ b/crates/libs/bindgen/src/rust/classes.rs @@ -257,7 +257,7 @@ fn type_is_exclusive(ty: &metadata::Type) -> bool { } fn is_default_async(interfaces: &[metadata::Interface]) -> Option<&metadata::Interface> { - let pos = interfaces.iter().position(|interface| { + interfaces.iter().find(|interface| { if interface.kind == metadata::InterfaceKind::Default { if let metadata::Type::TypeDef(def, _) = interface.ty { if matches!( @@ -272,23 +272,5 @@ fn is_default_async(interfaces: &[metadata::Interface]) -> Option<&metadata::Int } } false - }); - - if let Some(pos) = pos { - if interfaces.len() == 1 { - return interfaces.get(0); - } - - if interfaces.len() == 2 { - let info = if pos == 0 { 1 } else { 0 }; - - if let metadata::Type::TypeDef(def, _) = interfaces[info].ty { - if def.type_name() == metadata::TypeName::IAsyncInfo { - return interfaces.get(pos); - } - } - } - } - - None + }) } diff --git a/crates/tests/futures/tests/tests.rs b/crates/tests/futures/tests/tests.rs index 9e08bde7fb..ac4b30441b 100644 --- a/crates/tests/futures/tests/tests.rs +++ b/crates/tests/futures/tests/tests.rs @@ -45,7 +45,7 @@ fn stream_async() -> Result<()> { fn switch_context() -> Result<()> { use futures::{executor::LocalPool, future, task::SpawnExt}; use std::future::IntoFuture; - + let mut pool = LocalPool::new(); let (sender, receiver) = std::sync::mpsc::channel::<()>(); @@ -65,8 +65,8 @@ fn switch_context() -> Result<()> { } }) .unwrap(); - - let async_future = pool.run_until(select); + + let async_future = pool.run_until(select); pool.spawner() .spawn(async move { @@ -82,4 +82,4 @@ fn switch_context() -> Result<()> { pool.run(); Ok(()) -} \ No newline at end of file +} From 766e263f90b908d932cdb2303e943184c3639f98 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 20 Aug 2024 19:40:27 -0500 Subject: [PATCH 4/5] cleanup --- crates/libs/metadata/src/type_name.rs | 1 - .../libs/windows/src/extensions/Foundation/Async.rs | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/libs/metadata/src/type_name.rs b/crates/libs/metadata/src/type_name.rs index e90e083495..19160a7ad6 100644 --- a/crates/libs/metadata/src/type_name.rs +++ b/crates/libs/metadata/src/type_name.rs @@ -15,7 +15,6 @@ impl TypeName { pub const HResult: Self = Self("Windows.Foundation", "HResult"); pub const IAsyncAction: Self = Self("Windows.Foundation", "IAsyncAction"); - pub const IAsyncInfo: Self = Self("Windows.Foundation", "IAsyncInfo"); pub const IAsyncActionWithProgress: Self = Self("Windows.Foundation", "IAsyncActionWithProgress"); pub const IAsyncOperation: Self = Self("Windows.Foundation", "IAsyncOperation"); diff --git a/crates/libs/windows/src/extensions/Foundation/Async.rs b/crates/libs/windows/src/extensions/Foundation/Async.rs index b4f53e3837..60c620af3d 100644 --- a/crates/libs/windows/src/extensions/Foundation/Async.rs +++ b/crates/libs/windows/src/extensions/Foundation/Async.rs @@ -26,8 +26,9 @@ pub trait Async: Interface { fn get_results(&self) -> Result; } -// The `AsyncFuture` is needed to store some extra state needed to keep async execution up to date with possible changes to Rust execution context. -// Each async type implements `IntoFuture` rather than implementing `Future` directly so that this adapter may be used. +// The `AsyncFuture` is needed to store some extra state needed to keep async execution up to date with possible changes +// to Rust execution context. Each async type implements `IntoFuture` rather than implementing `Future` directly so that +// this adapter may be used. pub struct AsyncFuture { // Represents the async execution and provides the virtual methods for setting up a `Completed` handler and // calling `GetResults` when execution is completed. @@ -38,7 +39,7 @@ pub struct AsyncFuture { // A shared waker is needed to keep the `Completed` handler updated. // - `Option` is used to avoid allocations for async objects that have already completed. - // - `Arc` is used to share the `Waker` with the `Completed` handler and and potentially replace the `Waker` + // - `Arc` is used to share the `Waker` with the `Completed` handler and potentially replace the `Waker` // since we don't have the ability to replace the `Completed` handler itself. // - `Mutex` is used to synchronize replacing the `Waker` across threads. waker: Option>>, @@ -63,8 +64,6 @@ impl Future for AsyncFuture { type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - println!("poll {cx:?}"); - // A status of `Started` just means async execution is still in flight. Since WinRT async is always // "hot start", if its not `Started` then its ready for us to call `GetResults` so we can skip all of // the remaining set up. @@ -74,8 +73,8 @@ impl Future for AsyncFuture { if let Some(shared_waker) = &self.waker { // We have a shared waker which means we're either getting polled again or been transfered to - // another another execution context. Either way, we need to update the shared waker to make sure - // we've got the "current" waker. + // another execution context. As we can't tell the difference, we need to update the shared waker + // to make sure we've got the "current" waker. let mut guard = shared_waker.lock().unwrap(); guard.clone_from(cx.waker()); From 3ac549055e777116ffd7dccf6127c92aa2bb4bf0 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 20 Aug 2024 19:53:58 -0500 Subject: [PATCH 5/5] yml --- .github/workflows/clippy.yml | 2 ++ .github/workflows/test.yml | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index b8959b991f..d349de0f4e 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -171,6 +171,8 @@ jobs: run: cargo clippy -p test_event - name: Clippy test_extensions run: cargo clippy -p test_extensions + - name: Clippy test_futures + run: cargo clippy -p test_futures - name: Clippy test_handles run: cargo clippy -p test_handles - name: Clippy test_helpers diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe68bd00f3..3b00cb88ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -197,6 +197,8 @@ jobs: run: cargo test -p test_event --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_extensions run: cargo test -p test_extensions --target ${{ matrix.target }} ${{ matrix.etc }} + - name: Test test_futures + run: cargo test -p test_futures --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_handles run: cargo test -p test_handles --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_helpers @@ -253,10 +255,10 @@ jobs: run: cargo test -p test_riddle --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_standalone run: cargo test -p test_standalone --target ${{ matrix.target }} ${{ matrix.etc }} - - name: Test test_string_param - run: cargo test -p test_string_param --target ${{ matrix.target }} ${{ matrix.etc }} - name: Clean run: cargo clean + - name: Test test_string_param + run: cargo test -p test_string_param --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_strings run: cargo test -p test_strings --target ${{ matrix.target }} ${{ matrix.etc }} - name: Test test_structs