Skip to content

Commit

Permalink
Remove Future implementation (#3142)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Jul 3, 2024
1 parent 9f96662 commit 12a60df
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 278 deletions.
19 changes: 0 additions & 19 deletions crates/libs/bindgen/src/rust/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Output> {
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())
}
}
}
}
}
}
Expand Down
96 changes: 0 additions & 96 deletions crates/libs/windows/src/Windows/Devices/Sms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Output> {
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);
Expand Down Expand Up @@ -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<Self::Output> {
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);
Expand Down Expand Up @@ -1243,22 +1211,6 @@ impl GetSmsDeviceOperation {
}
}
#[cfg(feature = "deprecated")]
impl std::future::Future for GetSmsDeviceOperation {
type Output = windows_core::Result<SmsDevice>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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);
Expand Down Expand Up @@ -1347,22 +1299,6 @@ impl GetSmsMessageOperation {
self.GetResults()
}
}
#[cfg(feature = "deprecated")]
impl std::future::Future for GetSmsMessageOperation {
type Output = windows_core::Result<ISmsMessage>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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)]
Expand Down Expand Up @@ -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<super::super::Foundation::Collections::IVectorView<ISmsMessage>>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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)]
Expand Down Expand Up @@ -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<Self::Output> {
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);
Expand Down
60 changes: 0 additions & 60 deletions crates/libs/windows/src/Windows/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Output> {
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 {
Expand Down Expand Up @@ -198,21 +183,6 @@ impl<TProgress: windows_core::RuntimeType + 'static> IAsyncActionWithProgress<TP
self.GetResults()
}
}
impl<TProgress: windows_core::RuntimeType + 'static> std::future::Future for IAsyncActionWithProgress<TProgress> {
type Output = windows_core::Result<()>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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<TProgress: windows_core::RuntimeType + 'static> Send for IAsyncActionWithProgress<TProgress> {}
unsafe impl<TProgress: windows_core::RuntimeType + 'static> Sync for IAsyncActionWithProgress<TProgress> {}
impl<TProgress: windows_core::RuntimeType + 'static> windows_core::RuntimeType for IAsyncActionWithProgress<TProgress> {
Expand Down Expand Up @@ -368,21 +338,6 @@ impl<TResult: windows_core::RuntimeType + 'static> IAsyncOperation<TResult> {
self.GetResults()
}
}
impl<TResult: windows_core::RuntimeType + 'static> std::future::Future for IAsyncOperation<TResult> {
type Output = windows_core::Result<TResult>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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<TResult: windows_core::RuntimeType + 'static> Send for IAsyncOperation<TResult> {}
unsafe impl<TResult: windows_core::RuntimeType + 'static> Sync for IAsyncOperation<TResult> {}
impl<TResult: windows_core::RuntimeType + 'static> windows_core::RuntimeType for IAsyncOperation<TResult> {
Expand Down Expand Up @@ -500,21 +455,6 @@ impl<TResult: windows_core::RuntimeType + 'static, TProgress: windows_core::Runt
self.GetResults()
}
}
impl<TResult: windows_core::RuntimeType + 'static, TProgress: windows_core::RuntimeType + 'static> std::future::Future for IAsyncOperationWithProgress<TResult, TProgress> {
type Output = windows_core::Result<TResult>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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<TResult: windows_core::RuntimeType + 'static, TProgress: windows_core::RuntimeType + 'static> Send for IAsyncOperationWithProgress<TResult, TProgress> {}
unsafe impl<TResult: windows_core::RuntimeType + 'static, TProgress: windows_core::RuntimeType + 'static> Sync for IAsyncOperationWithProgress<TResult, TProgress> {}
impl<TResult: windows_core::RuntimeType + 'static, TProgress: windows_core::RuntimeType + 'static> windows_core::RuntimeType for IAsyncOperationWithProgress<TResult, TProgress> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Output> {
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)]
Expand Down Expand Up @@ -602,21 +587,6 @@ impl UserAuthenticationOperation {
self.GetResults()
}
}
impl std::future::Future for UserAuthenticationOperation {
type Output = windows_core::Result<UserIdentity>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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)]
Expand Down
30 changes: 0 additions & 30 deletions crates/libs/windows/src/Windows/Storage/Streams/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,21 +1325,6 @@ impl DataReaderLoadOperation {
self.GetResults()
}
}
impl std::future::Future for DataReaderLoadOperation {
type Output = windows_core::Result<u32>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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)]
Expand Down Expand Up @@ -1608,21 +1593,6 @@ impl DataWriterStoreOperation {
self.GetResults()
}
}
impl std::future::Future for DataWriterStoreOperation {
type Output = windows_core::Result<u32>;
fn poll(self: std::pin::Pin<&mut Self>, context: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
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)]
Expand Down
3 changes: 0 additions & 3 deletions crates/samples/windows/ocr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
futures = "0.3.5"

[dependencies.windows]
path = "../../../libs/windows"
features = [
Expand Down
14 changes: 5 additions & 9 deletions crates/samples/windows/ocr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
1 change: 0 additions & 1 deletion crates/tests/winrt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ features = [
]

[dev-dependencies]
futures = "0.3"
helpers = { package = "test_helpers", path = "../helpers" }
Loading

0 comments on commit 12a60df

Please sign in to comment.