Ferrous API Reference

All Types / Ferrous

class NewtypeAttribute

public sealed class NewtypeAttribute : Attribute

Marks a readonly partial struct as a zero-overhead Rust-style newtype wrapper around UnderlyingType. Ferrous.Unions generates Value, equality, comparison, parsing, span formatting, [NoDefault], and a NativeAOT-safe System.Text.Json converter.

Constructors

public NewtypeAttribute(Type underlyingType)

Initializes a new NewtypeAttribute wrapping underlyingType.

Parameters
underlyingType
The wrapped underlying type (e.g., typeof(Guid) or typeof(int)).

Properties

public Type UnderlyingType

Gets the wrapped underlying type.

public bool GenerateJsonConverter

Gets or sets whether to emit a NativeAOT-safe System.Text.Json converter when System.Text.Json is referenced. Defaults to true.

public bool AllowDefault

Gets or sets whether to allow default initialization without [NoDefault] enforcement. Defaults to false (emits [NoDefault]).