Zeeshan Adil
Book a call
← Rust for C# Engineers: From Garbage Collection to Ownership and Lifetimes

Chapter 16 of 16 · Closing

What I would actually do in your first month

by Zeeshan AdilUpdated 9 min read
Listen to this articleLearn Rust as a C# Developer: A First-Month Plan 10 min · read by an AI voice
0:00 / 9:48

A first month with Rust for .NET engineers: toolchain setup, reading compiler diagnostics, a four-week learning order, the traps to avoid and editions.

Use this as a practice plan after the foundations, or as a place to return when the amount of material feels overwhelming. The aim is a small working program and a repeatable way to investigate compiler errors, not memorizing every chapter.

Everything above is the model. This is the practice: what to install, what to build, what order to learn things in, and which well-intentioned first projects will waste your week.

The toolchain, and why it feels different

Install through rustup rather than a package manager. It manages toolchains the way a version manager does, and it is what every piece of documentation assumes you have.

Code
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup component add clippy rustfmt

cargo then does the job of dotnet, NuGet, MSBuild and your test runner at once. The commands worth knowing on day one:

CommandWhat it does.NET equivalent
cargo new namescaffold a projectdotnet new console
cargo checktypecheck without producing a binaryno real equivalent, and you will miss it
cargo build --releaseoptimized builddotnet build -c Release
cargo runbuild and rundotnet run
cargo testunit, integration and documentation testsdotnet test
cargo add serdeadd a dependency and edit the manifestdotnet add package
cargo clippythe lint pass that teaches you idiomanalyzers, but better
cargo fmtformat, non-negotiablydotnet format
cargo doc --openbuild and open your API docsDocFX, without the setup

cargo check provides type and borrow checking without producing the final executable. It is usually faster than a full build, although timing depends on the project. Still run builds and tests: code generation, linking, and runtime behavior can expose problems that checking alone does not.

Unit tests commonly live beside the code they test, inside #[cfg(test)] modules. Integration tests can live separately under tests/. Rust documentation tests can also compile and run examples with cargo test. The library example below assumes a crate named hostname_check; use your own crate name in the import. These tests validate examples, not every claim in the prose.

Code
/// Returns true for hostnames inside the internal zone.
///
/// ```
/// use hostname_check::is_internal;
/// assert!(is_internal("db-1.internal"));
/// assert!(!is_internal("example.com"));
/// ```
pub fn is_internal(host: &str) -> bool {
    host.ends_with(".internal")
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn rejects_external_hosts() {
        assert!(!is_internal("example.com"));
    }
}

Learn to read the diagnostics properly

Rust's error messages are the best I have used in any language, and reading them fully rather than skimming to the first plausible change is the single habit that shortens the learning curve most.

A diagnostic has a consistent shape: an error code, a one-line summary, the primary span with a caret under the offending expression, one or more secondary spans showing the other end of the conflict, and then note and help lines. The secondary span is the part people skip, and it is usually where the actual answer is, because a borrow error is never about one location. It is about two locations that cannot both be true.

When the summary is not enough, rustc --explain E0502 prints several paragraphs on that specific error class with a worked example. There is no equivalent in the .NET tooling and it is genuinely useful in the first month.

Clippy deserves a paragraph of its own. It is not a style checker with opinions about braces. It knows the idiomatic form of hundreds of patterns and will tell you that your loop should be an iterator chain, that your match is a map, or that you are cloning something you could borrow. Treating its output as a tutorial rather than as noise will teach you idiom faster than reading code will.

A four-week shape

Week one, get ownership into your hands. Write a command line tool that reads files and prints something about them. Word counts, a log filter, anything with a real input. Do not model anything with a graph in it. The only goal is that moves stop surprising you.

Clone freely while you do it. Your instinct on the first borrow error will be to fight it for twenty minutes. Write .clone(), keep moving, and leave a comment. Optimizing code you have not finished writing is a waste, and the allocation you are avoiding is almost never one that matters.

Week two, take the clones back out one at a time and let the compiler explain why each one existed. This is where &str against String, and &[T] against Vec<T>, stop being trivia and start being a decision you make deliberately. By the end of it you should be able to look at a function signature and say what it does to its arguments without reading the body, which is a thing you cannot do in C#.

Week three, traits and error handling. Define your own error enum, implement From for the errors you wrap, use ? throughout, and derive Debug, Clone and PartialEq on your types. Add thiserror when writing the conversions by hand gets tedious. Most of what looks like magic in a good Rust codebase turns out to be a trait implementation you have not read yet.

Week four, pick a direction based on what you actually build. For services, go to async: futures, Tokio, and why Send bounds propagate up through everything. For libraries and tools, go to generics and dispatch: monomorphization, dyn, and when each one is right.

Leave unsafe until you have a reason. Read the Rustonomicon then, not before.

The traps, specifically

Do not implement a linked list. It is the classic first data structure and it is unusually hostile in Rust, because a doubly linked list needs shared mutable ownership and drops you into Rc<RefCell<T>> or raw pointers before you understand either. There is an entire well-known book about how bad an idea this is. Write a parser, a log filter, or a small HTTP client instead.

Do not start with an async web service. It stacks async, lifetimes, trait bounds and an unfamiliar framework on top of ownership, all in week one, and when something confuses you there will be no way to tell which of the four is responsible. Write something synchronous first.

Do not port a C# design directly. The class hierarchy with an abstract base and three overrides does not translate, and forcing it produces the worst Rust you will ever write. Ask what data is owned by whom first, then work out where the behavior goes. Composition and traits usually land somewhere simpler than the hierarchy you started with.

Do not reach for Rc<RefCell<T>> on the first borrow error. It is the shape that makes Rust feel like C# again, which is exactly why it is tempting, and it trades compile-time errors for run-time panics. Try restructuring so ownership forms a tree, or use indices into a central Vec, before you decide the type system is the problem.

Do not fight a lifetime error for an hour. If a struct holding references is causing pain in month one, take the allocation. Own the data, move on, and come back when the borrow checker is somewhere you can think in.

Editions, briefly

Editions are opt-in language revisions. They let the language change syntax and idiom without breaking crates written years earlier, because each crate declares which edition it was written against and the compiler handles the mix. The edition guide records what changed in each one.

For a new project this needs no thought: cargo new picks the current edition and you move on. It matters when you read old blog posts, because pre-2018 code has a different module system and different lifetime behavior, and following it will confuse you for reasons that have nothing to do with your code.

The thing to take away

Go back to the first paragraph of this guide. borrow of moved value is not the compiler being pedantic. It is the compiler asking who owns this, and when does it die, which is a question every program has to answer whether or not the language makes you say it. C# answers it at run time, by tracing what is still reachable and reclaiming the rest. You get to not think about it, and you pay in a runtime, in pause behavior under load, and in an entire category of aliasing bug that only appears when two things touch the same object at an unlucky moment.

Rust demands the answer at compile time. In exchange it deletes the collector, inserts deterministic cleanup at scope exits, while still permitting leaks and aborts that skip destruction, and turns data races into type errors. The frustration of week one is the price of the answer, and it drops sharply once you stop reading the borrow checker as an obstacle and start reading it as a question you were always supposed to have answered.

Neither answer is better in general. They are different points on the same trade, and knowing both makes you better at choosing between them, including when the right choice is the one you already have. Most of what you know about .NET still applies, because a hash map is still a hash map and a thread pool is still a thread pool. What changes is that the thing you were allowed to leave implicit now has to be said out loud, in the signature, where the next person can read it.

Checking yourself

Why is cargo check worth binding to your editor rather than cargo build? It provides type and borrow-checking feedback without producing a final executable, often much faster. Keep builds and tests in your workflow because code generation, linking, and execution can reveal additional failures.

What is the first thing to try when a borrow error appears, before reaching for Rc<RefCell<T>>? Clone, or restructure so ownership forms a tree. Interior mutability trades a compile-time error for a possible run-time panic, and it is rarely the cheapest fix in the first month.

Why do editions exist, given that Rust promises backward compatibility? They let syntax and idiom change without breaking old crates, because the edition is declared per crate and the compiler links them together. Backward compatibility is preserved at the ecosystem level rather than by freezing the language.

Get the next deep dive by email

New deep dives on how production systems really behave, from Kubernetes networking to PostgreSQL internals. About one email a month.

You will get one email to confirm. Unsubscribe from any email with one click. Your address is used for this newsletter and nothing else.

Written by Zeeshan Adil

I run systems like this for a living. If your team is fighting the same problem, or wants this as a talk, write to me.