Skip to main content

Crate csharp_rs

Crate csharp_rs 

Source
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§

CSharpNamespace
A validated C# namespace (e.g. "Company.Product").
Config
Runtime configuration for C# code generation.

Enums§

CSharpFieldInfo
Metadata for a C# field, used by #[serde(flatten)] to inline properties.
CSharpVersion
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 T to path.

Derive Macros§

CSharp
Re-export of the derive macro from csharp-rs-macros. Derives a C# type definition for the annotated Rust type.