diff --git a/crates/libs/bindgen/src/rust/writer.rs b/crates/libs/bindgen/src/rust/writer.rs index 80fdd47924..3da4429bcc 100644 --- a/crates/libs/bindgen/src/rust/writer.rs +++ b/crates/libs/bindgen/src/rust/writer.rs @@ -697,25 +697,6 @@ impl Writer { self.GetResults() } } - #features - impl<#constraints> std::future::Future for #ident { - type Output = windows_core::Result<#return_type>; - - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == #namespace AsyncStatus::Started { - let waker = context.waker().clone(); - - let _ = self.SetCompleted(&#namespace #handler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } - } } } } diff --git a/crates/libs/windows/src/Windows/Devices/Sms/mod.rs b/crates/libs/windows/src/Windows/Devices/Sms/mod.rs index 9f77b79a18..64d785eda9 100644 --- a/crates/libs/windows/src/Windows/Devices/Sms/mod.rs +++ b/crates/libs/windows/src/Windows/Devices/Sms/mod.rs @@ -1036,22 +1036,6 @@ impl DeleteSmsMessageOperation { } } #[cfg(feature = "deprecated")] -impl std::future::Future for DeleteSmsMessageOperation { - type Output = windows_core::Result<()>; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} -#[cfg(feature = "deprecated")] #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] pub struct DeleteSmsMessagesOperation(windows_core::IUnknown); @@ -1138,22 +1122,6 @@ impl DeleteSmsMessagesOperation { } } #[cfg(feature = "deprecated")] -impl std::future::Future for DeleteSmsMessagesOperation { - type Output = windows_core::Result<()>; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} -#[cfg(feature = "deprecated")] #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] pub struct GetSmsDeviceOperation(windows_core::IUnknown); @@ -1243,22 +1211,6 @@ impl GetSmsDeviceOperation { } } #[cfg(feature = "deprecated")] -impl std::future::Future for GetSmsDeviceOperation { - type Output = windows_core::Result; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} -#[cfg(feature = "deprecated")] #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] pub struct GetSmsMessageOperation(windows_core::IUnknown); @@ -1347,22 +1299,6 @@ impl GetSmsMessageOperation { self.GetResults() } } -#[cfg(feature = "deprecated")] -impl std::future::Future for GetSmsMessageOperation { - type Output = windows_core::Result; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} #[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] @@ -1471,22 +1407,6 @@ impl GetSmsMessagesOperation { self.GetResults() } } -#[cfg(all(feature = "Foundation_Collections", feature = "deprecated"))] -impl std::future::Future for GetSmsMessagesOperation { - type Output = windows_core::Result>; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncOperationWithProgressCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} #[cfg(feature = "deprecated")] #[repr(transparent)] #[derive(PartialEq, Eq, Debug, Clone)] @@ -1573,22 +1493,6 @@ impl SendSmsMessageOperation { self.GetResults() } } -#[cfg(feature = "deprecated")] -impl std::future::Future for SendSmsMessageOperation { - type Output = windows_core::Result<()>; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} #[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 1ba0d86d51..a414916d61 100644 --- a/crates/libs/windows/src/Windows/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/mod.rs @@ -78,21 +78,6 @@ impl IAsyncAction { self.GetResults() } } -impl std::future::Future for IAsyncAction { - type Output = windows_core::Result<()>; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&AsyncActionCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} unsafe impl Send for IAsyncAction {} unsafe impl Sync for IAsyncAction {} impl windows_core::RuntimeType for IAsyncAction { @@ -198,21 +183,6 @@ impl IAsyncActionWithProgress std::future::Future for IAsyncActionWithProgress { - type Output = windows_core::Result<()>; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&AsyncActionWithProgressCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} unsafe impl Send for IAsyncActionWithProgress {} unsafe impl Sync for IAsyncActionWithProgress {} impl windows_core::RuntimeType for IAsyncActionWithProgress { @@ -368,21 +338,6 @@ impl IAsyncOperation { self.GetResults() } } -impl std::future::Future for IAsyncOperation { - type Output = windows_core::Result; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&AsyncOperationCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} unsafe impl Send for IAsyncOperation {} unsafe impl Sync for IAsyncOperation {} impl windows_core::RuntimeType for IAsyncOperation { @@ -500,21 +455,6 @@ impl std::future::Future for IAsyncOperationWithProgress { - type Output = windows_core::Result; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&AsyncOperationWithProgressCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(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 0b7d2f15cc..e82467d540 100644 --- a/crates/libs/windows/src/Windows/Security/Authentication/OnlineId/mod.rs +++ b/crates/libs/windows/src/Windows/Security/Authentication/OnlineId/mod.rs @@ -504,21 +504,6 @@ impl SignOutUserOperation { self.GetResults() } } -impl std::future::Future for SignOutUserOperation { - type Output = windows_core::Result<()>; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::super::Foundation::AsyncActionCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} unsafe impl Send for SignOutUserOperation {} unsafe impl Sync for SignOutUserOperation {} #[repr(transparent)] @@ -602,21 +587,6 @@ impl UserAuthenticationOperation { self.GetResults() } } -impl std::future::Future for UserAuthenticationOperation { - type Output = windows_core::Result; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} unsafe impl Send for UserAuthenticationOperation {} unsafe impl Sync for UserAuthenticationOperation {} #[repr(transparent)] diff --git a/crates/libs/windows/src/Windows/Storage/Streams/mod.rs b/crates/libs/windows/src/Windows/Storage/Streams/mod.rs index b9e13fe009..51059b48e8 100644 --- a/crates/libs/windows/src/Windows/Storage/Streams/mod.rs +++ b/crates/libs/windows/src/Windows/Storage/Streams/mod.rs @@ -1325,21 +1325,6 @@ impl DataReaderLoadOperation { self.GetResults() } } -impl std::future::Future for DataReaderLoadOperation { - type Output = windows_core::Result; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} unsafe impl Send for DataReaderLoadOperation {} unsafe impl Sync for DataReaderLoadOperation {} #[repr(transparent)] @@ -1608,21 +1593,6 @@ impl DataWriterStoreOperation { self.GetResults() } } -impl std::future::Future for DataWriterStoreOperation { - type Output = windows_core::Result; - fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll { - if self.Status()? == super::super::Foundation::AsyncStatus::Started { - let waker = context.waker().clone(); - let _ = self.SetCompleted(&super::super::Foundation::AsyncOperationCompletedHandler::new(move |_sender, _args| { - waker.wake_by_ref(); - Ok(()) - })); - std::task::Poll::Pending - } else { - std::task::Poll::Ready(self.GetResults()) - } - } -} unsafe impl Send for DataWriterStoreOperation {} unsafe impl Sync for DataWriterStoreOperation {} #[repr(transparent)] diff --git a/crates/samples/windows/ocr/Cargo.toml b/crates/samples/windows/ocr/Cargo.toml index e75742439e..377ff0e03a 100644 --- a/crates/samples/windows/ocr/Cargo.toml +++ b/crates/samples/windows/ocr/Cargo.toml @@ -4,9 +4,6 @@ version = "0.0.0" edition = "2021" publish = false -[dependencies] -futures = "0.3.5" - [dependencies.windows] path = "../../../libs/windows" features = [ diff --git a/crates/samples/windows/ocr/src/main.rs b/crates/samples/windows/ocr/src/main.rs index 7672ece94d..4dc85d8d06 100644 --- a/crates/samples/windows/ocr/src/main.rs +++ b/crates/samples/windows/ocr/src/main.rs @@ -6,22 +6,18 @@ use windows::{ }; fn main() -> Result<()> { - futures::executor::block_on(main_async()) -} - -async fn main_async() -> Result<()> { let mut message = std::env::current_dir().unwrap(); message.push("message.png"); let file = - StorageFile::GetFileFromPathAsync(&HSTRING::from(message.to_str().unwrap()))?.await?; - let stream = file.OpenAsync(FileAccessMode::Read)?.await?; + StorageFile::GetFileFromPathAsync(&HSTRING::from(message.to_str().unwrap()))?.get()?; + let stream = file.OpenAsync(FileAccessMode::Read)?.get()?; - let decode = BitmapDecoder::CreateAsync(&stream)?.await?; - let bitmap = decode.GetSoftwareBitmapAsync()?.await?; + let decode = BitmapDecoder::CreateAsync(&stream)?.get()?; + let bitmap = decode.GetSoftwareBitmapAsync()?.get()?; let engine = OcrEngine::TryCreateFromUserProfileLanguages()?; - let result = engine.RecognizeAsync(&bitmap)?.await?; + let result = engine.RecognizeAsync(&bitmap)?.get()?; println!("{}", result.Text()?); Ok(()) diff --git a/crates/tests/winrt/Cargo.toml b/crates/tests/winrt/Cargo.toml index fa09f0050f..10c6bf801f 100644 --- a/crates/tests/winrt/Cargo.toml +++ b/crates/tests/winrt/Cargo.toml @@ -29,5 +29,4 @@ features = [ ] [dev-dependencies] -futures = "0.3" helpers = { package = "test_helpers", path = "../helpers" } diff --git a/crates/tests/winrt/tests/async.rs b/crates/tests/winrt/tests/async.rs index 44a843fd5c..8ce9a224ae 100644 --- a/crates/tests/winrt/tests/async.rs +++ b/crates/tests/winrt/tests/async.rs @@ -23,33 +23,3 @@ fn async_get() -> windows::core::Result<()> { Ok(()) } - -async fn async_await() -> windows::core::Result<()> { - use windows::Storage::Streams::*; - - 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 test_async_await() -> windows::core::Result<()> { - futures::executor::block_on(async_await()) -}