com/lib.rs
1//! A helper crate for consuming and producing COM interfaces.
2//!
3//! # Example
4//!
5//! To work with a COM interface it must first be declared:
6//!
7//! ```rust,no_run
8//! /// Define an IAnimal interface
9//! com::interfaces! {
10//! #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
11//! pub unsafe interface IAnimal: com::interfaces::IUnknown {
12//! unsafe fn Eat(&self) -> com::sys::HRESULT;
13//! }
14//! }
15//! # fn main() {}
16//! ```
17//!
18//! To define a COM implementation class:
19//!
20//! ```rust,no_run
21//! # com::interfaces! {
22//! # #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
23//! # pub unsafe interface IAnimal: com::interfaces::IUnknown {
24//! # unsafe fn Eat(&self) -> com::sys::HRESULT;
25//! # }
26//! # }
27//! com::class! {
28//! pub class BritishShortHairCat: IAnimal {
29//! num_owners: u32,
30//! }
31//!
32//! impl IAnimal for BritishShortHairCat {
33//! fn Eat(&self) -> com::sys::HRESULT {
34//! println!("Eating...");
35//! com::sys::NOERROR
36//! }
37//! }
38//! }
39//! # fn main() {}
40//! ```
41//!
42//! See the examples directory in the repository for more examples.
43//!
44
45#![allow(clippy::transmute_ptr_to_ptr)]
46#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
47#![deny(missing_docs)]
48
49mod abi_transferable;
50mod interface;
51pub mod interfaces;
52mod param;
53#[doc(hidden)]
54pub mod refcounting;
55#[cfg(windows)]
56pub mod runtime;
57pub mod sys;
58
59#[cfg(feature = "production")]
60/// Functionality for producing COM classes
61pub mod production;
62
63#[doc(inline)]
64pub use abi_transferable::AbiTransferable;
65#[doc(inline)]
66pub use interface::Interface;
67#[doc(inline)]
68pub use param::Param;
69#[doc(inline)]
70pub use sys::{CLSID, IID};
71
72/// Declare COM interfaces
73///
74/// # Example
75/// ```rust,no_run
76/// /// Define an IAnimal interface
77/// com::interfaces! {
78/// #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
79/// pub unsafe interface IAnimal: com::interfaces::IUnknown {
80/// unsafe fn Eat(&self) -> com::sys::HRESULT;
81/// }
82/// }
83/// # fn main() {}
84/// ```
85pub use com_macros::interfaces;
86
87/// Declare COM implementation classes
88///
89/// # Example
90/// ```rust,no_run
91/// use com::sys::{HRESULT, NOERROR};
92/// # com::interfaces! {
93/// # #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
94/// # pub unsafe interface IAnimal: com::interfaces::IUnknown {
95/// # unsafe fn Eat(&self) -> com::sys::HRESULT;
96/// # }
97/// # }
98///
99/// com::class! {
100/// pub class BritishShortHairCat: IAnimal {
101/// num_owners: u32,
102/// }
103///
104/// impl IAnimal for BritishShortHairCat {
105/// fn Eat(&self) -> HRESULT {
106/// println!("Eating...");
107/// NOERROR
108/// }
109/// }
110/// }
111/// # fn main() {}
112/// ```
113#[cfg(feature = "production")]
114pub use com_macros::class;
115
116// this allows for the crate to refer to itself as `com` to keep macros consistent
117// whether they are used by some other crate or internally
118#[doc(hidden)]
119extern crate self as com;
120
121// We re-export `alloc` so that we can use `com::alloc::boxed::Box` in generated code,
122// for code that uses `#![no_std]`.
123#[doc(hidden)]
124pub extern crate alloc;