Skip to main content

Crate hao_runtime_macros

Crate hao_runtime_macros 

Source
Expand description

Generates Rust bindings for a .NET assembly, for use with hao-runtime.

ⓘ
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);

Options:

  • assembly = "path": the assembly, relative to the crate’s Cargo.toml.
  • assembly_env = "VAR": read the path from an environment variable at compile time instead, e.g. one set by a build script.
  • framework = "Name": an assembly of the installed .NET, such as System.Private.CoreLib, found when compiling. CoreCLR only.
  • types = ["Ns.Type", ...]: only bind these types (nested types use +).

Every public, non-generic class gets a struct in a module named after its namespace. Public, non-generic methods whose parameters are primitives, strings or classes are bound. Static methods and constructors take the Runtime to call into.

Macros§

bind
Generates bindings for a .NET assembly. See the crate docs.