Skip to main content

Module rust

Module rust 

Source
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 Rust enum because the native side may hand over flag combinations or values added later);
  • struct S -> #[repr(C)] struct S with snake_case fields;
  • interface IFoo:
    • IFooVtbl — #[repr(C)] table of unsafe extern "system" fn slots, starting with the base interface’s table (the calling convention of COM: stdcall on 32-bit x86 Windows, the C convention everywhere else);
    • IFoo — #[repr(C)] struct holding the vtable pointer; a *mut IFoo is the native interface pointer, &IFoo derefs 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 owning ComPtr<IFoo>.

Signature mapping shared by proxies and Impl traits:

IDLRust
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* pp: Option<&IFoo> (borrowed)
char* s / [const] char* ss: Option<&CStr>
[const] T& rr: &T
other pointersraw pointers (proxy is unsafe fn)
boolbool (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 type names the Rust type of NAME (the counterpart of the @clr-map lines of the IDL files of the C# generator): @rust-map HWND isize, @rust-map REFIID *const Guid;
  • @rust-types-from path imports everything path has 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§

RustOptions

Functions§

generate
snake_case
GetClientSize -> get_client_size, texImageIOSurface2D -> tex_image_io_surface2d, RootProvider_GetWindow -> root_provider_get_window.