Skip to main content

csharp_fn

Macro csharp_fn 

Source
csharp_fn!() { /* proc-macro */ }
Expand description

Re-export the proc macros so users only need to depend on this crate. Return a typed Rust function that compiles and runs C# at program runtime.

Like csharp!, but supports parameters. The parameters declared in the C# Run(P1 p1, P2 p2, ...) method become the Rust function’s parameters. Arguments are serialised by Rust and piped to the C# process via stdin; C# reads them with BinaryReader.

Expands to a function value of type fn(P1, P2, ...) -> Result<T, CsharpError>.

§Examples

use inline_csharp::csharp_fn;

let double_it = csharp_fn! {
    static int Run(int n) {
        return n * 2;
    }
};
let result: i32 = double_it(21).unwrap();
assert_eq!(result, 42);