Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Runtime configuration for C# code generation.

Controls namespace, serializer library, C# language version, and export directory. Construct with Config::default and customize with builder methods.

§Examples

use csharp_rs::{Config, Serializer, CSharpVersion};

let cfg = Config::default()
    .with_serializer(Serializer::Newtonsoft)
    .with_target(CSharpVersion::CSharp11);

Implementations§

Source§

impl Config

Source

pub fn from_env() -> Self

Creates a configuration from environment variables.

Reads the following environment variables, falling back to defaults for missing or invalid values:

  • CSHARP_RS_EXPORT_DIR — output directory (default: "./csharp-bindings")
  • CSHARP_RS_SERIALIZER"stj" or "newtonsoft" (default: "stj")
  • CSHARP_RS_TARGET"unity", "9", "10", "11", "12" (default: "9")
  • CSHARP_RS_NAMESPACE — C# namespace (default: "Generated")
Source

pub fn with_namespace(self, ns: &str) -> Self

Sets the root namespace. Panics if the value is not a valid C# namespace.

§Panics

Panics if ns fails CSharpNamespace validation.

Source

pub fn with_validated_namespace(self, ns: CSharpNamespace) -> Self

Sets the root namespace from a pre-validated CSharpNamespace.

Source

pub fn with_serializer(self, serializer: Serializer) -> Self

Sets the target serializer library.

Source

pub fn with_target(self, target: CSharpVersion) -> Self

Sets the target C# language version.

Source

pub fn with_export_dir(self, dir: impl Into<PathBuf>) -> Self

Sets the export directory for generated .cs files.

Source

pub fn namespace(&self) -> &str

Returns the configured namespace as a string slice.

Source

pub fn serializer(&self) -> Serializer

Returns the configured serializer.

Source

pub fn target(&self) -> CSharpVersion

Returns the configured C# target version.

Source

pub fn export_dir(&self) -> &Path

Returns the configured export directory.

Trait Implementations§

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.