Skip to main content

Module bindings

Module bindings 

Source
Expand description

Support code for bindings generated by hao-runtime-macros.

The generated thunk assembly has a static type THUNK_TYPE with methods f0, f1, … The first helper::COUNT are the helpers below, the rest wrap the bound methods. Every thunk returns void, takes its arguments followed by an optional pointer to the return value and a pointer that receives a GCHandle to any exception thrown. Objects are passed as GCHandles.

None of this is called by hand: bind! generates a BoundAssembly and a struct per class wrapping an Object, which looks like this to use:

ⓘ
// Needs the `hao-runtime-macros` crate, which isn't a dependency of this
// one, and a built `dotnet/MyLib.dll` next to the calling crate.
mod my_lib {
    hao_runtime_macros::bind! {
        assembly = "dotnet/MyLib.dll",
    }
}

let runtime = hao_runtime::Runtime::coreclr()?;
let calculator = my_lib::my_lib::Calculator::new(&runtime, 10)?;
assert_eq!(calculator.add(5)?, 15);
// The wrapped `Object` gives the managed `ToString()`.
println!("{}", calculator.object().to_managed_string()?);

Modules§

helper
Indexes of the helper thunks every generated thunk assembly starts with.

Structs§

BoundAssembly
A .NET assembly bound with hao_runtime_macros::bind!.
Object
An owned reference to a managed object.

Constants§

THUNK_TYPE
The full name of the static type holding the thunks in every generated thunk assembly.