Expand description
Generate C# type definitions from Rust structs and enums.
csharp-rs provides a derive macro that generates C# class, record,
or enum definitions from Rust types. It respects serde attributes
for JSON serialization compatibility, making it ideal for sharing
types between a Rust backend and a C#/.NET or Unity client.
§Examples
use csharp_rs::CSharp;
#[derive(CSharp)]
#[csharp(namespace = "Game.Types")]
pub struct PlayerProfile {
pub name: String,
pub level: i32,
pub score: Option<f64>,
}Structs§
- CSharp
Namespace - A validated C# namespace (e.g.
"Company.Product"). - Config
- Runtime configuration for C# code generation.
Enums§
- CSharp
Field Info - Metadata for a C# field, used by
#[serde(flatten)]to inline properties. - CSharp
Version - Target C# language version — controls which syntax features are used.
- Serializer
- Which JSON serializer library to target in generated C# code.
Traits§
- CSharp
- Generates a C# type definition as a string.
Functions§
- export_
to - Writes the C# definition of
Ttopath.
Derive Macros§
- CSharp
- Re-export of the derive macro from
csharp-rs-macros. Derives a C# type definition for the annotated Rust type.