{"canonical_url":"https://engineer.company/glossary/rust/","content_markdown":"# Rust\n\n## What it is\n\nRust is a programming language for the work traditionally done in C and C++,\nwhere a program manages its own memory and is often linked into software written\nin other languages. Its compiler produces native machine code ahead of time.\nVersion 1.0 was announced on 15 May 2015 as a language combining low-level\ncontrol over performance with safety guarantees, reached without a garbage\ncollector or a runtime, which is what lets a Rust library stand in for a C one.\n\nMemory is managed through ownership, a set of rules the compiler checks. Each\nvalue has one owner at a time, and once the owner leaves its scope, the value is\ndropped and its memory freed, at a point fixed when the program is compiled\nrather than whenever a collector next looks. Code that needs a value without\ntaking it borrows a reference, and the borrowing rules allow, at any moment,\neither one mutable reference or any number of immutable ones, and require every\nreference to be valid. A program that breaks a rule does not compile. The same\nrules exclude data races, so two threads writing to the same data without\nsynchronisation is a compile error rather than an intermittent fault.\n\nRust has no exceptions. A function that can fail in an expected way returns a\n`Result`, holding either a value or an error, and the compiler warns by default if the caller leaves the result unused; a bug the\nprogram cannot recover from, such as reading past the end of an array, goes\nthrough the `panic!` macro instead.\n\nStatic analysis is conservative, so the compiler rejects some programs that\nwould have been fine, and some work, such as driving hardware or calling another\nlanguage, cannot be checked at all. For those cases there is `unsafe`, which\nunlocks five extra abilities, among them dereferencing a raw pointer and calling\nan unsafe function, which by default includes any function declared from C. It\ndoes not switch off the borrow checker; it marks the lines where the programmer,\nnot the compiler, vouches for memory safety, so the safety of those operations depends on the programmer maintaining their contracts, including in surrounding safe code. The Rust Book's advice is to keep those blocks small\nand wrap them in a safe interface, which is how parts of the standard library\nare built.\n\nA new compiler is released every six weeks. Changes that would break existing\ncode wait for an edition, which arrives every three years or so. There are four,\n2015, 2018, 2021 and 2024, and the newest became stable on 20 February 2025 with\nRust 1.85.0. Each package names its edition in `Cargo.toml`, every compiler\nbuilds all the editions that came before it, and packages of different editions\nlink together, so a project moves up when it chooses. Cargo, the dependency\nmanager and build tool, is included with the language, rustfmt keeps the code\nstyle consistent, and third-party libraries arrive as packages called crates.\n\n## Why it matters\n\nIn C and C++, a pointer used after its memory has been freed, or two threads\nwriting the same data, compiles without complaint and fails later,\nintermittently and often far from the cause. Rust turns those programs into\ncompile errors, and because the checks run at build time, the finished program\npays nothing for them.\n\nWith no garbage collector and no runtime to carry along, Rust code can sit\nunderneath software in other languages. Anything that can call C can call a Rust\ncore through a C interface, so one well-tested implementation can serve clients\non several platforms. The Rust Book lists command-line tools, web services,\nembedded devices and major parts of the Firefox web browser among its production\nuses.\n\nThe cost is paid up front. Code has to be shaped so that the compiler can see it\nis safe, which often means deciding who owns a value instead of passing\nreferences around freely, and the Book itself says that ownership takes time to\nget used to. When the compiler refuses a program it cannot verify, the answer is\nusually a different structure rather than a way around the check.\n\nStability is the other half of the bargain. Since 1.0, breaking changes have\nbeen largely ruled out, so a change that could break old code arrives only\nthrough an edition that a package opts into.\n\n## What it looks like in practice\n\nIn the portfolio, Rust is the core underneath\n[a native macOS messaging client](/portfolio/built-a-native-macos-client-in-swift-6/):\nthe protocol's well-tested core is written in Rust and exposes a C interface,\nand the client, 11,141 lines of Swift across 53 files, links it as a static\narchive compiled from a pinned upstream revision. Pinning matters because the C\ninterface is the contract: a moving core changes the contract without changing a\nline of Swift. Everything the C interface returns carries an ownership rule, and\ngetting one wrong produces a leak or a crash with no compiler warning in\nbetween, so a thin wrapper owns every pointer and every string that crosses the\nboundary, and no layer above it sees a raw pointer.\n\nLinking that core into an application means shipping everything it depends on,\nwhich is the subject of\n[a licence audit of 644 Rust crates](/portfolio/know-the-licence-of-everything-you-ship/).\nEach crate declares its licence as an expression, and the audit checks every\nexpression in the full dependency graph against an allow list on every build,\nreading OR as a choice between licences and AND as an obligation to honour both.\nAnything unmatched fails the build. Because a check that has never failed looks\nthe same as one that cannot, it was made to fail twice on purpose: once by\nrewriting a crate's licence to a term the list rejects, and once by moving the\npinned core revision without regenerating the audit. It reads declared metadata\nonly and is not legal advice.\n\nThis site has no Rust source of its own; it meets the language at one remove,\nthrough Ruff, which is written in Rust and checks every Python script a commit\ntouches.\n\n## Where it goes wrong\n\nMost Rust trouble sits at the edges of what the compiler checks: arithmetic in\nan optimised build, the boundary with another language, and code that arrives\nwith a dependency.\n\n**Arithmetic wraps in a release build.** A counter that panicked with an\noverflow during testing turns silently into a small number in production. In\ndebug builds Rust checks integer arithmetic for overflow and panics; a build\nwith `--release` leaves the check out and wraps around, so 256 in a `u8` becomes\n0, and the Book treats relying on that wrap as an error. Where a value can\noverflow, choose the behaviour explicitly: `checked_*` returns `None`,\n`saturating_*` stops at the limit and `wrapping_*` wraps on purpose.\n\n```rust\nfn add_stock(on_hand: u8, delivered: u8) -\u003e Option\u003cu8\u003e {\n    // None when the sum does not fit, in debug and release alike\n    on_hand.checked_add(delivered)\n}\n```\n\n**Memory bugs come back at the C boundary.** A program whose Rust side builds\nwithout a single warning leaks memory or crashes inside a foreign call.\nFunctions declared in an `extern` block are unsafe to call because the other\nlanguage enforces none of Rust's rules, so who frees each pointer is a\nconvention the compiler cannot see. Put one wrapper in charge of every pointer\nand string that crosses, write each ownership rule down beside the call, and\nexpose only a safe interface above it.\n\n**A panic reaches C and the process aborts.** A Rust function called from C\npanics, and instead of an error the whole program stops. Since Rust 1.81,\nreleased on 5 September 2024, a panic that tries to leave a function declared\nwith the plain `\"C\"` interface aborts the process. Turn failures into return\nvalues before they reach the boundary, and declare a function with `\"C-unwind\"`\nonly where the code on the other side expects to unwind.\n\n**A routine update changes the licence of the whole build.** A version bump\nthree levels down brings in a crate whose licence the product cannot accept, and\nnothing in the build says so. Each crate declares its own licence, and the\nobligations add up across the whole graph. Check every crate's expression\nagainst an allow list on every build, fail on anything unmatched, and break the\ncheck on purpose once to prove that it fires.\n\n## Further reading\n\n- [The Rust Programming Language](https://doc.rust-lang.org/book/) — the\n  official book, from installation through ownership, error handling and unsafe\n  code.\n- [What Is Ownership?](https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html)\n  — the three ownership rules and how memory is freed without a garbage\n  collector.\n- [Unsafe Rust](https://doc.rust-lang.org/book/ch20-01-unsafe-rust.html) — the\n  five unsafe abilities, raw pointers and calling C through `extern`.\n- [The Manifest Format](https://doc.rust-lang.org/cargo/reference/manifest.html)\n  — the `edition`, `rust-version` and `license` fields of `Cargo.toml`.\n- [Announcing Rust 1.0](https://blog.rust-lang.org/2015/05/15/Rust-1.0/) — the\n  original aims and the stability promise that began with 1.0.\n\n\u003chttps://engineer.company/glossary/rust/\u003e\n","date_modified":"2026-11-12T05:34:23Z","description":"How Rust frees memory by ownership instead of a garbage collector, how editions let it change safely, and where its guarantees stop at a C boundary.","formats":{"gemtext":"https://engineer.company/glossary/rust/index.gmi","gopher":"https://engineer.company/glossary/rust/gophermap","html":"https://engineer.company/glossary/rust/","json":"https://engineer.company/glossary/rust/index.json","markdown":"https://engineer.company/glossary/rust/index.md","pdf":"https://engineer.company/glossary/rust/index.pdf"},"kind":"page","language":"en","title":"What is Rust?","url":"https://engineer.company/glossary/rust/","version":1}