# Rust for C# Engineers: From Garbage Collection to Ownership and Lifetimes

> A book-length guide to Rust for engineers who already know C#. Fifteen chapters on ownership, borrowing, lifetimes, traits, generics, errors, concurrency, async and unsafe, each one anchored on the .NET model you already carry in your head.

- Author: Zeeshan Adil (https://www.internalswithzee.com/about)
- Published: 2026-09-06
- Updated: 2026-11-21
- Source: https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers

## The short version

- A guide that ports your .NET mental model to Rust instead of teaching syntax from scratch.
- Rust asks at compile time what the CLR answers at run time: who owns a value and how long a reference lives.
- Fifteen chapters cover ownership, borrowing, lifetimes, traits, generics, errors, concurrency, async and unsafe.
- Each chapter stands on its own after the foundations, so you can jump to what you are building.

Your first real Rust error will probably be `borrow of moved value`. You wrote something that would be fine in C#, the compiler refused it, and the honest reaction is that the language is being difficult for no reason.

It is not. It is asking you a question that the CLR answers for you at run time, and it wants the answer before the program runs.

That question leads into ownership, borrowing, and lifetimes. Once those ideas fit together, the differences in strings, error handling, concurrency, and async become easier to follow.

So this is not a syntax tour. You already know how to write a loop. This is an attempt to port your mental model. You have one for .NET, built over years, that tells you where objects live, who cleans them up, what happens when two threads touch the same list, and roughly what the JIT will do with your generics. Most of that model is still useful. Some of it is actively wrong in Rust, and the wrong parts are what make people bounce off the language in week two.

### What this assumes about you

You can write C# methods, classes, and collections, and you have used interfaces, generics, and exceptions. Some familiarity with value types, reference types, and garbage collection will help. You do not need to know Rust or have written C++.

The later chapters use .NET threads, `async`/`await`, LINQ, and `IDisposable` as comparisons. If those are unfamiliar, take the foundations first and return to the relevant chapter when you need it. The examples use .NET 9 and C# 13 unless a section says otherwise.

### How to read it

Your first goal is to explain three things: who owns a value, who is borrowing it, and how long that borrow can remain valid. You can learn those without first understanding every detail of the allocator or JIT.

Choose a route that matches what you need:

| Your goal | Reading route | Save for later |
| --- | --- | --- |
| Write your first Rust program | Read the six foundations chapters in order, then [errors](/blog/rust-guide-for-csharp-dotnet-engineers/rust-result-vs-csharp-exceptions), [optional values](/blog/rust-guide-for-csharp-dotnet-engineers/rust-option-vs-csharp-null), and the [first-month plan](/blog/rust-guide-for-csharp-dotnet-engineers/learning-rust-first-month-plan). | Detailed layout measurements, dispatch internals, and unsafe implementation. |
| Design a library or understand an existing API | After ownership, borrowing, and lifetimes, read [traits](/blog/rust-guide-for-csharp-dotnet-engineers/rust-traits-vs-csharp-interfaces), [generics](/blog/rust-guide-for-csharp-dotnet-engineers/rust-generics-monomorphization-vs-dotnet), and error handling. | Threading and async until the API needs them. |
| Build concurrent or async work | Start with the foundations, then read [interior mutability](/blog/rust-guide-for-csharp-dotnet-engineers/rust-interior-mutability-rc-refcell), [thread safety](/blog/rust-guide-for-csharp-dotnet-engineers/rust-send-sync-and-fearless-concurrency), and [async](/blog/rust-guide-for-csharp-dotnet-engineers/rust-async-await-vs-csharp-tasks). | Performance tuning until you have a working example to measure. |

Within each chapter, follow one example through before reading every aside. Predict its result, run it, and change one thing. For a deliberately broken example, being able to explain the compiler error is the useful outcome.

Here is the full chapter order for when you want the longer explanation.

**Part I, Foundations.** These six chapters are load-bearing and the rest of the book assumes them.

1. [The trade Rust is actually making](/blog/rust-guide-for-csharp-dotnet-engineers/the-trade-rust-is-making)
2. [Reading Rust when you already know C#](/blog/rust-guide-for-csharp-dotnet-engineers/rust-syntax-for-csharp-engineers)
3. [Where your data actually lives](/blog/rust-guide-for-csharp-dotnet-engineers/rust-stack-heap-box-and-strings)
4. [Ownership, and the rule that replaced the collector](/blog/rust-guide-for-csharp-dotnet-engineers/rust-ownership-and-moves)
5. [Borrowing, and why the compiler counts your references](/blog/rust-guide-for-csharp-dotnet-engineers/rust-borrowing-and-the-borrow-checker)
6. [Lifetimes are not object lifetime](/blog/rust-guide-for-csharp-dotnet-engineers/rust-lifetimes-explained)

**Part II, Working knowledge.** How Rust does abstraction, and the two types you will touch in every function you write.

7. [Traits are interfaces that do not own your types](/blog/rust-guide-for-csharp-dotnet-engineers/rust-traits-vs-csharp-interfaces)
8. [Generics that compile to what you would have written by hand](/blog/rust-guide-for-csharp-dotnet-engineers/rust-generics-monomorphization-vs-dotnet)
9. [Errors are values, and you have to look at them](/blog/rust-guide-for-csharp-dotnet-engineers/rust-result-vs-csharp-exceptions)
10. [The null that is not there](/blog/rust-guide-for-csharp-dotnet-engineers/rust-option-vs-csharp-null)

**Part III, Concurrency and systems.** Where ownership starts paying for itself, and where async gets harder than it is in C#.

11. [Interior mutability, or breaking the rules on purpose](/blog/rust-guide-for-csharp-dotnet-engineers/rust-interior-mutability-rc-refcell)
12. [Fearless concurrency is a claim the type system makes](/blog/rust-guide-for-csharp-dotnet-engineers/rust-send-sync-and-fearless-concurrency)
13. [Async without a runtime in the box](/blog/rust-guide-for-csharp-dotnet-engineers/rust-async-await-vs-csharp-tasks)

**Part IV, Under the hood.** Advanced, and skippable on a first pass. Come back when you want the machinery.

14. [Zero-cost abstractions, and where the cost actually lands](/blog/rust-guide-for-csharp-dotnet-engineers/rust-zero-cost-abstractions-vs-linq)
15. [Unsafe is a smaller word than you think](/blog/rust-guide-for-csharp-dotnet-engineers/rust-unsafe-explained)

Then a chapter on what I would actually do in a first month, the sources worth reading next, and the questions people ask.

If you only read part of it, read Part I. Ownership, borrowing and lifetimes are not three features, they are one idea seen from three angles, and almost every later chapter is downstream of them.

Definition boxes explain terms as they appear. Other notes hold background or version details that you can return to after the main explanation.

Examples labeled as complete programs include their setup. Shorter snippets build on the surrounding types and functions; they are not all standalone files. Deliberate compiler failures are followed by the expected diagnostic. Keep those failing examples separate from a program you want to run.

## Chapters

1. [The trade Rust is actually making](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/the-trade-rust-is-making.md): What a tracing garbage collector buys a C# program, what its pauses cost, and how Rust moves that same safety work to compile time, with the real price.
2. [Reading Rust when you already know C#](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-syntax-for-csharp-engineers.md): Read Rust fluently if you know C#: expressions, let and mut, structs and impl blocks, exhaustive enums, modules, and where the syntax hides a real difference.
3. [Where your data actually lives](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-stack-heap-box-and-strings.md): Where Rust values live compared with C# class and struct: Box, String against &str, memory layout, padding, niche optimization and the C# habits to drop.
4. [Ownership, and the rule that replaced the collector](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-ownership-and-moves.md): The three ownership rules, what a move compiles to, Copy against Clone, and how Drop replaces using, for engineers used to the .NET garbage collector.
5. [Borrowing, and why the compiler counts your references](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-borrowing-and-the-borrow-checker.md): Why Rust allows many readers or one writer, the bug that rule prevents, how reborrowing and split borrows work, and how it compares with ref, out and in in C#.
6. [Lifetimes are not object lifetime](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-lifetimes-explained.md): A Rust lifetime is a region of code, not a duration. Annotations, the three elision rules, structs holding references and 'static, set against the C# GC.
7. [Traits are interfaces that do not own your types](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-traits-vs-csharp-interfaces.md): How Rust traits differ from C# interfaces: implementing them for types you do not own, the orphan rule, newtypes, associated types and blanket impls.
8. [Generics that compile to what you would have written by hand](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-generics-monomorphization-vs-dotnet.md): How Rust monomorphizes generics where the CLR shares code, when to choose dyn Trait and its vtable, impl Trait, dyn compatibility and what dispatch costs.
9. [Errors are values, and you have to look at them](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-result-vs-csharp-exceptions.md): Rust returns errors as values instead of throwing. How Result and the ? operator work, thiserror against anyhow, and how panic differs from an exception.
10. [The null that is not there](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-option-vs-csharp-null.md): How Option<T> represents missing values and compares with C# nullable reference types, how to use it without drowning in match, converting to Result, and its runtime cost.
11. [Interior mutability, or breaking the rules on purpose](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-interior-mutability-rc-refcell.md): When one owner and one writer is not enough: Rc, Cell, RefCell and Weak, reference cycles, arenas and indices, and where a C# garbage collector simply wins.
12. [Fearless concurrency is a claim the type system makes](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-send-sync-and-fearless-concurrency.md): How Send and Sync turn data races into compile errors, plus Arc, Mutex, poisoning, scoped threads, channels and Rayon, compared with lock, Task and PLINQ in C#.
13. [Async without a runtime in the box](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-async-await-vs-csharp-tasks.md): Rust futures are cold and need an executor, unlike hot C# Tasks. Wakers, cancellation by drop, join against WhenAll, Send bounds and Pin, for .NET engineers.
14. [Zero-cost abstractions, and where the cost actually lands](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-zero-cost-abstractions-vs-linq.md): What zero-cost really claims, how a Rust iterator pipeline compiles to a loop, what the LINQ version allocates, bounds checks, where the claim fails.
15. [Unsafe is a smaller word than you think](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/rust-unsafe-explained.md): The operations unsafe permits and the checks that still apply, why the boundary is the architecture, how it compares with C# unsafe code, and why you rarely need it.
16. [What I would actually do in your first month](https://www.internalswithzee.com/blog/rust-guide-for-csharp-dotnet-engineers/learning-rust-first-month-plan.md): A first month with Rust for .NET engineers: toolchain setup, reading compiler diagnostics, a four-week learning order, the traps to avoid and editions.

## Sources and further reading

Each chapter links its sources at the claim they support. This is the shorter list of things worth reading in full, rather than consulting.

**The official material, in the order it becomes useful**

- [The Rust Programming Language](https://doc.rust-lang.org/book/), the official book and still the best starting point. Chapters four and ten are the ones to read slowly.
- [The Rust Reference](https://doc.rust-lang.org/reference/) is the normative description of the language. Reach for it when you need to know what is guaranteed rather than what usually happens, particularly [type layout](https://doc.rust-lang.org/reference/type-layout.html) and [destructors](https://doc.rust-lang.org/reference/destructors.html), which settle most arguments about size and drop order.
- [The Rustonomicon](https://doc.rust-lang.org/nomicon/) is the book for unsafe Rust. [What unsafe does](https://doc.rust-lang.org/nomicon/what-unsafe-does.html) is two pages and worth reading even if you never write any, because it is the precise version of chapter fifteen.
- [The rustc dev guide](https://rustc-dev-guide.rust-lang.org/) explains what the compiler actually does. The chapter on [monomorphization](https://rustc-dev-guide.rust-lang.org/backend/monomorph.html) is the primary source behind chapter eight.
- [The Cargo book](https://doc.rust-lang.org/cargo/), specifically [profiles](https://doc.rust-lang.org/cargo/reference/profiles.html) and [the SemVer chapter](https://doc.rust-lang.org/cargo/reference/semver.html), which is unusually clear about what counts as a breaking change.

**The .NET side of each comparison**

- [Fundamentals of garbage collection](https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals) and the [garbage collection design document](https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/garbage-collection.md) from the Book of the Runtime. Worth reading precisely because Rust removes what they describe.
- [Generics in the runtime](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generics-in-the-run-time) on value type specialization and reference type sharing, and [guarded devirtualization](https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/jit/GuardedDevirtualization.md) on how the JIT recovers some of what monomorphization gives Rust for free.
- [How Async/Await Really Works in C#](https://devblogs.microsoft.com/dotnet/how-async-await-really-works/) by Stephen Toub. Read it before the Rust equivalent and chapter thirteen becomes obvious.
- [Span and Memory usage guidelines](https://learn.microsoft.com/en-us/dotnet/standard/memory-and-spans/memory-t-usage-guidelines) and [ref struct types](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/ref-struct). These are the borrow checker's rules written as advice for humans, applied to one corner of C#.
- [Nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/null-safety/nullable-reference-types), which is honest about being static analysis over a runtime that still has null.

**Going deeper**

- [Rust Atomics and Locks](https://mara.nl/atomics/) by Mara Bos, free online, and the best practical treatment of concurrency in the language.
- [Why async Rust?](https://without.boats/blog/why-async-rust/) by Without Boats on why the poll-based model was chosen, and [How Rust optimizes async/await](https://tmandry.gitlab.io/blog/posts/optimizing-await-1/) by Tyler Mandry on how futures are laid out across await points.
- Niko Matsakis on [modeling graphs with vector indices](https://smallcultfollowing.com/babysteps/blog/2015/04/06/modeling-graphs-in-rust-using-vector-indices/), which is the answer to most problems people try to solve with reference counting, and on [the orphan rule](https://smallcultfollowing.com/babysteps/blog/2015/01/14/little-orphan-impls/).
- [RFC 2094](https://rust-lang.github.io/rfcs/2094-nll.html) for non-lexical lifetimes and [the stabilization post](https://blog.rust-lang.org/2022/08/05/nll-by-default/). Reading the RFC is the fastest way to understand what the borrow checker is actually computing.
- [Peeking inside a Rust enum](https://fasterthanli.me/articles/peeking-inside-a-rust-enum) by Amos, which goes to the disassembly to show niche optimization happening.
- [The Rust Performance Book](https://nnethercote.github.io/perf-book/) for when something is measurably slow, and [Miri](https://github.com/rust-lang/miri) for when you have written unsafe code and want to know whether it is sound.

**On whether any of this is worth it**

- The Microsoft Security Response Center's [proactive approach to more secure code](https://www.microsoft.com/en-us/msrc/blog/2019/07/a-proactive-approach-to-more-secure-code) is the origin of the widely quoted 70% figure, and [we need a safer systems programming language](https://www.microsoft.com/en-us/msrc/blog/2019/07/we-need-a-safer-systems-programming-language) is the argument that followed it.
- The Chromium project's [memory safety page](https://www.chromium.org/Home/chromium-security/memory-safety/) is an independent measurement from a different large C++ codebase.
- Google's [Eliminating Memory Safety Vulnerabilities at the Source](https://security.googleblog.com/2024/09/eliminating-memory-safety-vulnerabilities-Android.html) is the strongest longitudinal data published so far, tracking what happened to Android as new code moved to memory-safe languages.

## Continue learning

A path rather than a pile.

Start by making ownership automatic. Write a small tool that reads files and prints something, and clone whenever the compiler complains. The goal is not efficiency, it is getting to the point where moves stop surprising you.

Then take the clones out one at a time and let the borrow checker explain why each existed. This is where owned against borrowed types stop being trivia and become a decision you make deliberately.

Once borrowing is comfortable, learn traits properly, especially the conversion traits, iterators and the derive macros. Most of what feels like magic in a good Rust codebase is a trait implementation you have not read yet.

After that, pick a direction based on what you build. For services, go to async: futures, Tokio, and why the Send bound propagates through everything. For libraries and tools, go to generics and dispatch.

Leave unsafe until last, and only if you need it.

Two things worth understanding alongside all of this, because they explain more than their size suggests: how memory layout and alignment decide what a struct actually costs, and how a tracing collector decides what is still reachable. The second is what makes the first chapter land.

## Frequently asked questions

**Do I need to know C or C++ first?**

No, and coming from C# is arguably an advantage. You already think in types and abstractions rather than in manual allocation, so what you are actually learning is where values live and who owns them, not pointer arithmetic. A C++ background helps with layout intuition and actively hurts with move semantics, because a C++ move leaves a valid, usable object behind and a Rust move does not. C++ engineers spend their first week discovering that the moved-from variable is gone at compile time rather than merely empty.

**Is Rust actually faster than C#?**

For most application code, not by enough to justify a rewrite. Modern .NET is a genuinely fast runtime, the JIT is very good, and if your bottleneck is a database query or a network round trip then the language is not what is slow.

Rust can be attractive for tail latency, memory budgets, and startup time. Removing a tracing collector removes one source of pauses, but allocation, destruction, locks, page faults, I/O, and scheduling still affect latency. Memory use depends on representation and allocator behavior, and .NET Native AOT changes the startup comparison. Benchmark the workload you intend to ship.

Throughput, tail latency, memory use, and startup time are separate measurements. Decide which constraint matters before comparing implementations.

**How long before I am productive?**

Two to four weeks to write useful code if you are already senior. Two to three months before the borrow checker stops being the main thing you are thinking about. The curve is unusually front-loaded, which is why the language has a reputation for being hard: most of the difficulty arrives in the first fortnight rather than being spread out, and people judge it from inside that window.

What flattens it fastest is resisting the urge to be efficient early. Clone, get the program working, and take the clones out once you understand why each one was there.

**Can I call Rust from .NET?**

Yes, and it is the sensible way to adopt it. Build the Rust side as a `cdylib` exposing `extern "C"` functions, then call it with `DllImport`, or with the `LibraryImport` source generator on .NET 7 and later.

The boundary is a C ABI, which carries no lifetime or ownership information, so marshalling and ownership across it are entirely your responsibility. The usual rules apply: decide which side allocates and which side frees, do not pass Rust `String` or `Vec` across directly, and expose a free function for anything Rust allocated. Taking the single hot component out of an existing service is a far better first project than a rewrite, and it lets you keep everything the .NET ecosystem is good at.

**Should I start with an async web service?**

No. It stacks async, lifetimes, trait bounds and an unfamiliar framework on top of ownership all at once, and when you get stuck you will not be able to tell which of the four is responsible. Write something synchronous and small first. You will get to the web service two weeks later and it will take an afternoon.

**Does Rust have a garbage collector?**

Rust has no mandatory tracing garbage collector. The compiler inserts drop operations, but their timing depends on runtime control flow; for `Rc` and `Arc`, the last strong reference determines when the payload is destroyed. Libraries can also implement tracing collectors when a design calls for one.

`Rc` and `Arc` do reference counting where shared ownership is genuinely needed. That is automatic memory management, but it is not a tracing collector and the difference matters: reference counting cannot collect cycles, so two values holding counted handles to each other leak. `Weak` is the fix, and it is a fix you have to remember to apply. This is the one place where .NET's collector is straightforwardly better than what Rust gives you, and it is worth saying plainly rather than defending.

**Does the borrow checker change how I design, or is it just a stricter compiler?**

It changes the design, and this is the part that is hard to convey before you have felt it.

In C#, ownership is a documentation concern. Who is allowed to mutate this list, who is responsible for disposing this handle, whether this array is safe to hand out or needs a defensive copy: all real questions, all answered in comments, conventions and code review. Rust moves those questions into the signature, so they get answered when you write the function rather than when someone violates the assumption six months later.

The practical effect is that data flow becomes a tree far more often than it does in C#, because a graph of mutable references is expensive to express and a tree is free. That constraint pushes designs toward clearer ownership than most of us would have arrived at unaided, which is the argument people mean when they say the borrow checker made them a better C# programmer too.

**What is the ecosystem genuinely missing compared to NuGet?**

Be realistic about this, because it is the most common reason a sensible Rust project fails.

Rust is strong where it grew up: networking, parsing, serialization, command line tools, cryptography, embedded, WebAssembly, and increasingly data infrastructure. Web frameworks and HTTP clients are good. Serialization through `serde` is better than anything in .NET.

It is weaker in enterprise integration. Object relational mapping exists but nothing has the maturity or the tooling of Entity Framework Core. Desktop UI is unsettled. Cloud provider SDKs have improved a great deal but coverage lags the .NET SDKs. Anything touching the Microsoft ecosystem specifically, from identity libraries to Office formats to line of business connectors, is thin or absent.

If your service is mostly translating HTTP into SQL, .NET has more of what you need and a rewrite buys you very little. If it is mostly moving bytes, parsing protocols or holding state in memory under latency pressure, the gap closes and often reverses.

**Is it worth learning if I will not use it at work?**

I think so, for a reason that has nothing to do with employment. Rust forces you to be explicit about ownership, aliasing and lifetime, and those concepts exist in every language you already use. They were simply invisible because the runtime was handling them.

After a few months of Rust, the aliasing bugs in C# code start to look obvious rather than unlucky. You notice which methods take a collection and quietly keep a reference to it. You notice which disposal paths are only correct by convention. Whether or not you ship a line of Rust, the model transfers, and that is a better argument for learning it than performance is.
