Ferrous 2.3.0
dotnet add package Ferrous --version 2.3.0
NuGet\Install-Package Ferrous -Version 2.3.0
<PackageReference Include="Ferrous" Version="2.3.0" />
<PackageVersion Include="Ferrous" Version="2.3.0" />
<PackageReference Include="Ferrous" />
paket add Ferrous --version 2.3.0
#r "nuget: Ferrous, 2.3.0"
#:package Ferrous@2.3.0
#addin nuget:?package=Ferrous&version=2.3.0
#tool nuget:?package=Ferrous&version=2.3.0
<p align="center"> <img src="https://raw.githubusercontent.com/bradwestness/Ferrous/main/assets/logo.png" alt="Ferrous Logo" width="128" height="128" /> </p>
Ferrous
Rust-grade compile-time safety, zero-allocation primitives, and Clippy-style diagnostics for .NET.
Ferrous brings Rust's engineering guarantees to C#—data-owning Mutex<T> / AsyncMutex<T>, zero-allocation ScopeGuard / Result<T, TError> / Option<T>, zero-boxing [DiscriminatedUnion] and [Newtype] source generators, CFG-based ownership / borrowing / typestate / resource-leak verification, and FE0001–FE0502 rustc-style diagnostics with IDE quick-fixes and the dotnet fe CLI.
Polyfill on
.NET 10, light up natively on.NET 11+/ C# 15+:[DiscriminatedUnion]emits native[Union]+TryGetValue,FE0400recognizes C# 15'sclosed(IsClosedTypeAttribute) hierarchies, and allnet11.0targets compile withruntime-async=onautomatically.
Packages
Install everything at once via the metapackage:
dotnet add package Ferrous
Or pick individual packages a la carte:
| Package | Category | Description |
|---|---|---|
Ferrous |
Metapackage | Pulls in all runtime libraries, source generators, and Roslyn analyzers |
Ferrous.Core |
Contracts | Shared attributes ([MustUse], [DiscriminatedUnion], [Newtype], [Consuming], [ConsumesSelf], [Borrow], [BorrowMut], [Typestate], [ThreadConfined], [NoDefault], [NoAlloc], [Checked], [Closed], [Immutable]) |
Ferrous.Guard |
Runtime | Zero-allocation ref struct scope guards (ScopeGuard.Defer(...)) |
Ferrous.Results |
Runtime | Allocation-free readonly struct Result<T, TError>, Option<T>, CheckedMath, NonZero<T>, NonEmptyString, NonEmptyList<T>, and safe .Get(...) |
Ferrous.Concurrency |
Runtime | Data-owning Mutex<T>, AsyncMutex<T>, RwLock<T>, AsyncRwLock<T>, OnceLock<T>, LazyLock<T>, TypedChannel, and structured concurrency TaskScope (.NET 11 runtime-async=on) |
Ferrous.Unions |
Generator | IIncrementalGenerator for zero-boxing [DiscriminatedUnion] (.NET 11 [Union] light-up, [ErrorMessage], JSON converters) and validated [Newtype] structs |
Ferrous.Annotations |
Analyzer | Roslyn analyzer (FE0001) enforcing [MustUse] on methods, constructors, types, and awaited tasks |
Ferrous.Ownership |
Analyzer | CFG-based Roslyn analyzers (FE0200–FE0203) enforcing move semantics and borrowing exclusivity/escape |
Ferrous.States |
Analyzer | Typestate protocol verifier (FE0300–FE0303) for linear state machines ([Typestate]) |
Ferrous.CodeFixes |
Code Fixes | Roslyn IDE quick-fixes for 15 rules (FE0001–FE0501) + on-demand Ctrl+. migration refactorings (throw → Result, T? → Option, primitive → [Newtype]) |
Ferrous.Pedantic |
Analyzer | Clippy-style pedantic lints (FE0400–FE0427, including bounds-aware indexing, inter-procedural summaries & Clippy parity) + <FerrousPedantic>true</FerrousPedantic> |
Ferrous.Concurrency.Analyzers |
Analyzer | Thread-safety analyzers (FE0500 !Send/[ThreadConfined], FE0501 mutable static state, FE0502 lock-across-await, FE0503 detached Task.Run in TaskScope) |
Ferrous.AspNetCore |
Web (Opt-In) | Minimal API Result/Option → IResult / RFC 7807 ProblemDetails extensions and .WithFerrousResults() endpoint filter (zero reflection, NativeAOT-ready) |
Ferrous.EntityFrameworkCore |
Data (Opt-In) | EF Core ValueConverters for NonEmptyString, NonZero<T>, and [Newtype] (UseFerrousConventions()) + FirstOrErrAsync / SingleOrErrAsync query helpers |
Ferrous.Testing |
Testing | trybuild-style CompileAssert, proptest-style PropAssert.ForAll + Gen<T> shrinking, Result/Option assertions, and AllocAssert.Zero |
Ferrous.Tool |
CLI Tool | dotnet fe global/local tool (expand, graph, init, audit, doctest, test, doc, migrate) |
Ferrous.Templates |
Template | dotnet new ferrous project template pre-wired with <FerrousPedantic>true</FerrousPedantic>, CPM, lockfiles, and NativeAOT |
Quick Examples
Scope Guards (Ferrous.Guard)
using Ferrous.Guard;
// Allocation-free with explicit state (no closure allocation)
using var guard = ScopeGuard.Defer(resource, static r => r.Release());
// Commit / rollback pattern
using var rollback = ScopeGuard.Defer(tx, static t => t.Rollback());
tx.Commit();
rollback.Dismiss();
Results & Options (Ferrous.Results)
using Ferrous.Results;
Result<int, string> ParsePort(string input) =>
int.TryParse(input, out int port) && port is > 0 and <= 65535
? Result.Ok<int, string>(port)
: Result.Err<int, string>($"Invalid port: {input}");
string message = ParsePort("8080")
.Map(p => p + 1)
.Match(
onOk: p => $"Listening on {p}",
onErr: err => $"Error: {err}");
Discriminated Unions (Ferrous.Unions)
using Ferrous;
[DiscriminatedUnion]
public readonly partial struct Shape
{
public static partial Shape Circle(double radius);
public static partial Shape Rect(double width, double height);
public static partial Shape Point();
}
// Works on .NET 10 and .NET 11 with zero boxing
double area = Shape.Circle(3.0).Match(
onCircle: r => Math.PI * r * r,
onRect: (w, h) => w * h,
onPoint: () => 0.0);
// On .NET 11 / C# 15, native exhaustive `switch` lights up automatically
double areaNet11 = Shape.Circle(3.0) switch
{
Shape.CircleCase c => Math.PI * c.radius * c.radius,
Shape.RectCase r => r.width * r.height,
Shape.PointCase => 0.0,
};
[MustUse] Analyzer (Ferrous.Annotations)
using Ferrous;
[MustUse("Check the error code.")]
int Save() => 0;
Save();
// warning FE0001: unused value of 'Save()' that must be used (note: Check the error code.);
// help: assign it to a variable or explicitly discard it with '_ = ...'
_ = Save(); // OK (explicit discard)
Ownership & Typestate Protocols (Ferrous.Ownership + Ferrous.States)
using Ferrous;
[Typestate(IsInitial = true)]
public sealed class Draft
{
public string Body { get; set; } = "";
[ConsumesSelf]
public Published Publish() => new Published();
}
[Typestate]
public sealed class Published { }
var draft = new Draft();
var published = draft.Publish(); // OK: consumes `draft`
_ = draft.Body;
// error FE0200: use of moved value 'draft': value moved into 'Publish()' at line 16;
// help: reassign 'draft' before reusing it, or avoid consuming it
_ = new Published();
// error FE0300: cannot construct non-initial typestate 'Published' directly;
// help: transition from an initial state via a [ConsumesSelf] method,
// or mark 'Published' with [Typestate(IsInitial = true)] if it is an entry state
Every FE* diagnostic follows a rustc-inspired format—concise problem summary, causal move-site location (wired into IDE AdditionalLocations so you can jump straight to where a value was moved), an actionable help: hint, and a clickable helpLinkUri pointing directly to the Wiki guide.
Rust-Grade Testing (Ferrous.Testing)
using Ferrous.Results;
using Ferrous.Testing;
// Framework-agnostic assertions (xUnit, NUnit, MSTest, TUnit)
int port = ParsePort("8080").AssertOk();
// Zero-allocation unit-test companion to [NoAlloc]
AllocAssert.Zero(static () => Result.Ok<int, string>(41).Map(static x => x + 1));
// trybuild-style compile-fail verification for [Typestate], [Consuming], [BorrowMut], etc.
CompileAssert.Fails("""
using Ferrous;
public static class Demo
{
public static void Take([Consuming] string s) { }
public static void Run() { var b = "hi"; Take(b); _ = b.Length; }
}
""", "FE0200");
CLI Tooling, Doc-Tests & Static API Docs (dotnet fe + dotnet new ferrous)
# Scaffold a new Rust-strict .NET app (CPM, lockfile, NativeAOT, <FerrousPedantic>true</FerrousPedantic>)
dotnet new install Ferrous.Templates
dotnet new ferrous -n MyApp
# Install the CLI tool
dotnet tool install -g Ferrous.Tool
# Build a zero-config, searchable static HTML API docs site with Roslyn syntax highlighting,
# full XML docs (exceptions, params, returns, examples), theme toggle, and Mermaid [Typestate] graphs
dotnet fe doc ./src --output ./docs-site --title "My API Reference" --logo ./assets/icon.png
# Run executable XML <example><code> & Markdown doc-tests (or both unit + doc tests together)
dotnet fe doctest ./src
dotnet fe test .
# Inspect generated [DiscriminatedUnion]/[Newtype] code, visualize [Typestate] graphs, and audit hygiene
dotnet fe expand ./src --type Shape
dotnet fe graph ./src --format mermaid --write README.md
dotnet fe audit . --packages --allow-licenses MIT --lockfile --semver --aot --cve
Live example: Ferrous dogfoods dotnet fe doc to publish its own API Reference on ferrous.westness.cc.
Target Frameworks
- Runtime packages target
net10.0andnet11.0(NativeAOT-compatible and trimmable). - Roslyn generators and analyzers target
netstandard2.0per Roslyn host requirements.
Building & Testing
dotnet format --verify-no-changes
dotnet build -c Release
dotnet test -c Release
See ferrous.westness.cc, ROADMAP.md for what's next, CHANGELOG.md for release notes, the API Reference (built with dotnet fe doc), and the Wiki for detailed guides.
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Ferrous.Annotations (>= 2.3.0)
- Ferrous.CodeFixes (>= 2.3.0)
- Ferrous.Concurrency (>= 2.3.0)
- Ferrous.Concurrency.Analyzers (>= 2.3.0)
- Ferrous.Core (>= 2.3.0)
- Ferrous.Guard (>= 2.3.0)
- Ferrous.Ownership (>= 2.3.0)
- Ferrous.Pedantic (>= 2.3.0)
- Ferrous.Results (>= 2.3.0)
- Ferrous.States (>= 2.3.0)
- Ferrous.Unions (>= 2.3.0)
-
net11.0
- Ferrous.Annotations (>= 2.3.0)
- Ferrous.CodeFixes (>= 2.3.0)
- Ferrous.Concurrency (>= 2.3.0)
- Ferrous.Concurrency.Analyzers (>= 2.3.0)
- Ferrous.Core (>= 2.3.0)
- Ferrous.Guard (>= 2.3.0)
- Ferrous.Ownership (>= 2.3.0)
- Ferrous.Pedantic (>= 2.3.0)
- Ferrous.Results (>= 2.3.0)
- Ferrous.States (>= 2.3.0)
- Ferrous.Unions (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.3.0 | 0 | 11/30/2026 |
| 2.2.0 | 0 | 11/30/2026 |
| 2.1.0 | 0 | 11/30/2026 |
| 2.0.0 | 0 | 11/30/2026 |
| 1.7.4 | 0 | 11/30/2026 |
| 1.7.3 | 0 | 11/30/2026 |
| 1.7.2 | 0 | 11/30/2026 |
| 1.7.1 | 0 | 11/30/2026 |
| 1.7.0 | 0 | 11/30/2026 |
| 1.6.0 | 0 | 11/30/2026 |
| 1.5.0 | 0 | 11/30/2026 |
| 1.4.0 | 37 | 11/30/2026 |
| 1.3.3 | 37 | 11/30/2026 |
| 1.3.2 | 49 | 11/30/2026 |
| 1.3.1 | 38 | 11/30/2026 |
| 1.3.0 | 45 | 11/30/2026 |
| 1.2.0 | 49 | 11/30/2026 |