Skip to content

Commit

Permalink
macro docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Nov 6, 2023
1 parent ab61477 commit 99dd3ea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
24 changes: 24 additions & 0 deletions crates/libs/implement/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
use quote::{quote, ToTokens};

/// Implements one or more COM interfaces.
///
/// # Example
/// ```rust,ignore
/// #[interface("094d70d6-5202-44b8-abb8-43860da5aca2")]
/// unsafe trait IValue: IUnknown {
/// fn GetValue(&self, value: *mut i32) -> HRESULT;
/// }
///
/// #[implement(IValue)]
/// struct Value(i32);
///
/// impl IValue_Impl for Value {
/// unsafe fn GetValue(&self, value: *mut i32) -> HRESULT {
/// *value = self.0;
/// HRESULT(0)
/// }
/// }
///
/// fn main() {
/// let object: IValue = Value(123).into();
/// // Call interface methods...
/// }
/// ```
#[proc_macro_attribute]
pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro::TokenStream) -> proc_macro::TokenStream {
let attributes = syn::parse_macro_input!(attributes as ImplementAttributes);
Expand Down
23 changes: 19 additions & 4 deletions crates/libs/interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ use quote::quote;
use syn::parse::{Parse, ParseStream};
use syn::spanned::Spanned;

/// A COM interface definition
/// Defines a COM interface to call or implement.
///
/// # Example
/// ```rust,ignore
/// #[windows_interface::interface("8CEEB155-2849-4ce5-9448-91FF70E1E4D9")]
/// unsafe trait IUIAnimationVariable: IUnknown {
/// fn GetValue(&self, value: *mut f64) -> HRESULT;
/// #[interface("094d70d6-5202-44b8-abb8-43860da5aca2")]
/// unsafe trait IValue: IUnknown {
/// fn GetValue(&self, value: *mut i32) -> HRESULT;
/// }
///
/// #[implement(IValue)]
/// struct Value(i32);
///
/// impl IValue_Impl for Value {
/// unsafe fn GetValue(&self, value: *mut i32) -> HRESULT {
/// *value = self.0;
/// HRESULT(0)
/// }
/// }
///
/// fn main() {
/// let object: IValue = Value(123).into();
/// // Call interface methods...
/// }
/// ```
#[proc_macro_attribute]
Expand Down
2 changes: 0 additions & 2 deletions crates/libs/windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ extern crate self as windows;
pub mod core {
pub use windows_core::*;

#[doc(hidden)]
#[cfg(feature = "implement")]
pub use windows_implement::implement;

#[doc(hidden)]
#[cfg(feature = "implement")]
pub use windows_interface::interface;
}
Expand Down

0 comments on commit 99dd3ea

Please sign in to comment.