Expand description
Proc-macro implementation for inline_csharp.
Provides three proc macros for embedding C# code in Rust:
| Macro | When it runs |
|---|---|
csharp! | program runtime |
csharp_fn! | program runtime |
ct_csharp! | compile time |
All macros require the user to write a static <T> Run(...) method
where T is one of: sbyte, byte, short, ushort, int, uint,
long, ulong, float, double, bool, char, string, T[],
List<T>, or T? — including arbitrarily nested types.
§Wire format (C# → Rust, stdout)
The macro generates a Main() that binary-serialises Run()’s return
value to stdout via BinaryWriter (raw UTF-8 for top-level string).
Encoding per type (all little-endian):
stringat top level: raw UTF-8 (no length prefix)stringinside a container: 4-byte LEu32length + UTF-8 bytes- scalar: fixed-width little-endian bytes via
BinaryWriter T[]/List<T>: 4-byte LEu32count + N × encode(T)T?(Nullable): 1-byte tag (0=null, 1=present) + encode(T) if present
§Wire format (Rust → C#, stdin)
Parameters declared in Run(...) are serialised by Rust and piped to the
child process’s stdin. C# reads them with BinaryReader.
§Options
All three macros accept zero or more key = "value" pairs before the C# body,
comma-separated. Recognised keys:
build = "<args>"— extra arguments passed verbatim todotnet buildrun = "<args>"— extra arguments passed verbatim todotnet runreference = "<path>"— add a reference assembly (repeatable)