-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COM interface impls move from MyApp to MyApp_Impl ("outer" object) #3065
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,18 @@ where | |
values: Vec<T::Default>, | ||
} | ||
|
||
impl<T> IIterable_Impl<T> for StockIterable<T> | ||
impl<T> IIterable_Impl<T> for StockIterable_Impl<T> | ||
where | ||
T: windows_core::RuntimeType, | ||
T::Default: Clone, | ||
{ | ||
fn First(&self) -> windows_core::Result<IIterator<T>> { | ||
unsafe { | ||
// TODO: ideally we can do an AddRef rather than a QI here (via cast)... | ||
// and then we can get rid of the unsafe as well. | ||
Ok(StockIterator { owner: self.cast()?, current: 0.into() }.into()) | ||
} | ||
use windows_core::IUnknownImpl; | ||
Ok(windows_core::ComObject::new(StockIterator { | ||
owner: self.to_object(), | ||
current: 0.into(), | ||
}) | ||
.into_interface()) | ||
} | ||
} | ||
|
||
|
@@ -27,52 +28,54 @@ where | |
T: windows_core::RuntimeType + 'static, | ||
T::Default: Clone, | ||
{ | ||
owner: IIterable<T>, | ||
owner: windows_core::ComObject<StockIterable<T>>, | ||
current: std::sync::atomic::AtomicUsize, | ||
} | ||
|
||
impl<T> IIterator_Impl<T> for StockIterator<T> | ||
impl<T> IIterator_Impl<T> for StockIterator_Impl<T> | ||
where | ||
T: windows_core::RuntimeType, | ||
T::Default: Clone, | ||
{ | ||
fn Current(&self) -> windows_core::Result<T> { | ||
let owner: &StockIterable<T> = unsafe { windows_core::AsImpl::as_impl(&self.owner) }; | ||
let owner: &StockIterable<T> = &self.owner; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much nicer. |
||
let current = self.current.load(std::sync::atomic::Ordering::Relaxed); | ||
|
||
if owner.values.len() > current { | ||
if self.owner.values.len() > current { | ||
T::from_default(&owner.values[current]) | ||
} else { | ||
Err(windows_core::Error::from(windows_core::imp::E_BOUNDS)) | ||
} | ||
} | ||
|
||
fn HasCurrent(&self) -> windows_core::Result<bool> { | ||
let owner: &StockIterable<T> = unsafe { windows_core::AsImpl::as_impl(&self.owner) }; | ||
let owner: &StockIterable<T> = &self.owner; | ||
let current = self.current.load(std::sync::atomic::Ordering::Relaxed); | ||
|
||
Ok(owner.values.len() > current) | ||
} | ||
|
||
fn MoveNext(&self) -> windows_core::Result<bool> { | ||
let owner: &StockIterable<T> = unsafe { windows_core::AsImpl::as_impl(&self.owner) }; | ||
let owner: &StockIterable<T> = &self.owner; | ||
let current = self.current.load(std::sync::atomic::Ordering::Relaxed); | ||
|
||
if current < owner.values.len() { | ||
self.current.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
self.current | ||
.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this just formatting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. These files weren't being run through rustfmt before. |
||
} | ||
|
||
Ok(owner.values.len() > current + 1) | ||
} | ||
|
||
fn GetMany(&self, values: &mut [T::Default]) -> windows_core::Result<u32> { | ||
let owner: &StockIterable<T> = unsafe { windows_core::AsImpl::as_impl(&self.owner) }; | ||
let owner: &StockIterable<T> = &self.owner; | ||
let current = self.current.load(std::sync::atomic::Ordering::Relaxed); | ||
|
||
let actual = std::cmp::min(owner.values.len() - current, values.len()); | ||
let (values, _) = values.split_at_mut(actual); | ||
values.clone_from_slice(&owner.values[current..current + actual]); | ||
self.current.fetch_add(actual, std::sync::atomic::Ordering::Relaxed); | ||
self.current | ||
.fetch_add(actual, std::sync::atomic::Ordering::Relaxed); | ||
Ok(actual as u32) | ||
} | ||
} | ||
|
@@ -85,6 +88,6 @@ where | |
type Error = windows_core::Error; | ||
fn try_from(values: Vec<T::Default>) -> windows_core::Result<Self> { | ||
// TODO: should provide a fallible try_into or more explicit allocator | ||
Ok(StockIterable { values }.into()) | ||
Ok(windows_core::ComObject::new(StockIterable { values }).into_interface()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, be nice if this simple case had a shorthand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still works; just being explicit. I can change this back, but I like the explicitness. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, can we implement
Into
/From
here as a shorthand for the simple case of returning the interface as before - then it would be similar to before:Ok(StockIterator {...}.into())
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
into()
thing still totally works. I just like theComObject::new(...).into_interface()
more because it's more explicit.