This adds a new type, ComObject<T>, which represents a type that was annotated with #[implement] and which has been placed in the heap. ComObject is conceptually similar to the ATL/MFC CComObject type.
The ComObject type and the #[implement] macro work together. They provide efficient (zero-cost) ways to cast to the interfaces that T implements. There are no runtime checks (and no addref/release), since we know at compile time that T implements those interfaces.
ComObject is a counted reference to the heap allocation that contains T. Its Clone implementation increments the reference count and its Drop implementation decrements the reference count.
Various other improvements;
The #[implement] and #[interface] macros can now be used in crates that are #![no_std]. The windows_core crate is not yet #![no_std], but I did convert a lot of std::foo to core::foo. I don't plan on getting all the way there in this PR, but this helps.
Added #[inline(always)] to many functions that are on important call paths. This is partly for performance but mainly for improving the debugging experience for stepping through interface dispatch. Right now, if you step into a call to a COM interface, you spend a lot of time stepping through 1-line functions, long before getting to the actual v-call.
Added unit tests for all new features in this PR.
ComObject has delegating implementations of many core Rust traits, such as Default, Hash, PartialEq, etc.
This adds a new type,
ComObject<T>
, which represents a type that was annotated with#[implement]
and which has been placed in the heap.ComObject
is conceptually similar to the ATL/MFCCComObject
type.The
ComObject
type and the#[implement]
macro work together. They provide efficient (zero-cost) ways to cast to the interfaces thatT
implements. There are no runtime checks (and no addref/release), since we know at compile time thatT
implements those interfaces.ComObject
is a counted reference to the heap allocation that containsT
. ItsClone
implementation increments the reference count and its Drop implementation decrements the reference count.Various other improvements;
#[implement]
and#[interface]
macros can now be used in crates that are#![no_std]
. Thewindows_core
crate is not yet#![no_std]
, but I did convert a lot ofstd::foo
tocore::foo
. I don't plan on getting all the way there in this PR, but this helps.#[inline(always)]
to many functions that are on important call paths. This is partly for performance but mainly for improving the debugging experience for stepping through interface dispatch. Right now, if you step into a call to a COM interface, you spend a lot of time stepping through 1-line functions, long before getting to the actual v-call.ComObject
has delegating implementations of many core Rust traits, such asDefault
,Hash
,PartialEq
, etc.