Expand description
Rust bindings generator.
For every IDL item the generated code contains:
- enum
E->#[repr(transparent)] struct E(pub i32)with one associated constant per member (a newtype rather than a Rustenumbecause the native side may hand over flag combinations or values added later); - struct
S->#[repr(C)] struct Swith snake_case fields; - interface
IFoo:IFooVtbl—#[repr(C)]table ofunsafe extern "system" fnslots, starting with the base interface’s table (the calling convention of COM:stdcallon 32-bit x86 Windows, the C convention everywhere else);IFoo—#[repr(C)]struct holding the vtable pointer; a*mut IFoois the native interface pointer,&IFooderefs to the base interface and carries the snake_case proxy methods;IFooImpl— the trait Rust code implements to provide the interface to native code,IFoo::from_impl(value)wraps an implementation into a COM object and returns the owningComPtr<IFoo>.
Signature mapping shared by proxies and Impl traits:
| IDL | Rust |
|---|---|
HRESULT M(...) | -> Result<(), HResult> |
HRESULT M(..., IFoo** ppv) (1) | -> Result<Option<ComPtr<IFoo>>, HResult> |
HRESULT M(..., T* ret) (1) | -> Result<T, HResult> |
IFoo* M() | -> Option<ComPtr<IFoo>> (owned) |
IFoo* p | p: Option<&IFoo> (borrowed) |
char* s / [const] char* s | s: Option<&CStr> |
[const] T& r | r: &T |
| other pointers | raw pointers (proxy is unsafe fn) |
bool | bool (C++ bool in the header) |
(1) only for a trailing parameter named ret, retOut, ppv or
result, or marked [out] or [retval]; every other pointer parameter
is passed through unchanged.
Types the IDL does not declare:
@rust-map NAME typenames the Rust type ofNAME(the counterpart of the@clr-maplines of the IDL files of the C# generator):@rust-map HWND isize,@rust-map REFIID *const Guid;@rust-types-from pathimports everythingpathhas into the generated code, where every other unknown name is looked up (the structures and enumerations a file declares beside its IDL):@rust-types-from super.
Structs§
Functions§
- generate
- snake_
case GetClientSize->get_client_size,texImageIOSurface2D->tex_image_io_surface2d,RootProvider_GetWindow->root_provider_get_window.