Convert Figma logo to code with AI

rust-lang logonomicon

The Dark Arts of Advanced and Unsafe Rust Programming

1,790
261
1,790
92

Top Related Projects

The Rust Reference

14,881

The Rust Programming Language

Learn Rust with examples (Live code editor included)

A guide to how rustc works and how to contribute to it.

5,878

RFCs for changes to Rust

Quick Overview

The rust-lang/nomicon repository contains the source for "The Rustonomicon," an advanced programming guide for Rust. It delves into unsafe Rust, explaining low-level details of the Rust programming language and how to use unsafe features correctly.

Pros

  • Provides in-depth knowledge about Rust's unsafe features
  • Helps developers understand the underlying mechanisms of Rust
  • Regularly updated to reflect changes in the Rust language
  • Written by Rust language experts and maintainers

Cons

  • Can be overwhelming for beginners
  • Focuses primarily on unsafe Rust, which is not recommended for most use cases
  • May require a solid understanding of systems programming concepts
  • Some sections may become outdated as Rust evolves

Getting Started

To access the Rustonomicon:

  1. Visit the official online version at https://doc.rust-lang.org/nomicon/
  2. Clone the repository for offline reading or contribution:
git clone https://github.com/rust-lang/nomicon.git
cd nomicon
  1. To build the book locally, install mdBook:
cargo install mdbook
  1. Then build and serve the book:
mdbook build
mdbook serve
  1. Open your web browser and navigate to http://localhost:3000 to view the locally built Rustonomicon.

Competitor Comparisons

The Rust Reference

Pros of Reference

  • More comprehensive coverage of Rust language features
  • Regularly updated with new language additions and changes
  • Clearer structure and organization for easier navigation

Cons of Reference

  • Less in-depth explanation of low-level implementation details
  • Fewer examples of unsafe code and its implications
  • More formal tone, which may be less engaging for some readers

Code Comparison

Reference:

fn main() {
    let x: i32 = 5;
    let y: i32 = 10;
    println!("x + y = {}", x + y);
}

Nomicon:

unsafe fn dangerous_function() {
    let raw_ptr: *mut i32 = std::ptr::null_mut();
    *raw_ptr = 42; // Undefined behavior!
}

The Reference provides a basic example of Rust syntax, while the Nomicon demonstrates unsafe code and potential pitfalls.

Summary

Reference is a comprehensive guide to Rust's language features, suitable for most developers. Nomicon focuses on advanced, unsafe Rust programming, offering deeper insights into low-level operations. Choose Reference for general language understanding and Nomicon for exploring Rust's more complex aspects.

14,881

The Rust Programming Language

Pros of book

  • More beginner-friendly, offering a comprehensive introduction to Rust
  • Regularly updated with new Rust features and best practices
  • Available in multiple formats (online, PDF, print) for easier accessibility

Cons of book

  • Less in-depth coverage of advanced topics and unsafe Rust
  • May not cover some low-level implementation details

Code comparison

book:

fn main() {
    let x = 5;
    println!("The value of x is: {}", x);
}

nomicon:

unsafe fn dangerous() {
    // Unsafe operations here
}

Summary

The book serves as an excellent starting point for Rust learners, providing a comprehensive overview of the language's features and concepts. It's regularly updated and accessible in various formats.

On the other hand, nomicon delves deeper into advanced topics, particularly unsafe Rust and low-level implementation details. It's more suitable for experienced Rust developers looking to understand the language's internals.

The code examples reflect this difference, with book focusing on basic concepts and nomicon demonstrating unsafe operations. While book is more approachable for beginners, nomicon offers valuable insights for those seeking to master Rust's advanced features and understand its underlying mechanisms.

Learn Rust with examples (Live code editor included)

Pros of Rust by Example

  • More beginner-friendly with practical, runnable examples
  • Covers a wider range of Rust concepts and features
  • Interactive learning experience with editable code snippets

Cons of Rust by Example

  • Less in-depth coverage of advanced topics
  • May not provide as much theoretical background
  • Updates less frequently than Nomicon

Code Comparison

Rust by Example:

fn main() {
    println!("Hello, world!");
}

Nomicon:

unsafe fn dangerous() {
    // ... unsafe operations ...
}

Summary

Rust by Example is an excellent resource for beginners and intermediate Rust developers, offering a hands-on approach to learning the language through practical examples. It covers a wide range of topics and provides an interactive learning experience.

On the other hand, Nomicon delves deeper into advanced Rust concepts, focusing on unsafe Rust and low-level details. It's more suitable for experienced Rust developers who want to understand the language's internals and advanced features.

While Rust by Example provides a broader overview of the language with runnable examples, Nomicon offers a more in-depth exploration of specific advanced topics. The choice between the two depends on the learner's experience level and learning goals.

A guide to how rustc works and how to contribute to it.

Pros of rustc-dev-guide

  • More comprehensive and detailed documentation for Rust compiler development
  • Regularly updated with the latest information on compiler internals
  • Includes practical guides for contributing to the Rust compiler project

Cons of rustc-dev-guide

  • Focuses primarily on compiler development, less useful for general Rust programming
  • May be overwhelming for beginners due to its technical depth
  • Lacks some of the low-level language details found in the Nomicon

Code Comparison

rustc-dev-guide example (simplified compiler pass):

fn run_pass<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
    for (bb, block) in body.basic_blocks.iter_enumerated_mut() {
        for statement in block.statements.iter_mut() {
            // Perform pass-specific operations on statements
        }
    }
}

Nomicon example (unsafe code):

let mut num = 5;
let r1 = &num as *const i32;
let r2 = r1 as *mut i32;
unsafe {
    *r2 = 10;
}

The rustc-dev-guide focuses on compiler internals and development processes, while the Nomicon delves into low-level language details and unsafe Rust. The code examples reflect this difference, with rustc-dev-guide showing compiler-specific code and the Nomicon demonstrating unsafe operations.

5,878

RFCs for changes to Rust

Pros of rfcs

  • Provides a structured process for proposing and discussing language changes
  • Offers a historical record of Rust's evolution and decision-making
  • Encourages community participation in shaping the language

Cons of rfcs

  • Can be overwhelming for newcomers due to the volume of technical discussions
  • May not provide immediate, practical guidance for using Rust
  • Requires more time to find specific information compared to a curated guide

Code comparison

While rfcs doesn't typically contain code snippets, nomicon often includes examples to illustrate unsafe Rust concepts:

nomicon:

let mut x = 0;
let y = &mut x;
let z = &mut *y;
*z = 1;
println!("{}", x);

rfcs generally contains more prose-based proposals and discussions rather than code examples.

Summary

nomicon serves as a guide for advanced and unsafe Rust programming, while rfcs is a repository for proposing and discussing changes to the Rust language. nomicon provides more direct, practical information for developers, while rfcs offers insight into the language's development process and future directions. Both repositories serve important but distinct purposes in the Rust ecosystem.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

The Rustonomicon

The Dark Arts of Advanced and Unsafe Rust Programming

Nicknamed "the Nomicon."

NOTE: This is a draft document, and may contain serious errors

Instead of the programs I had hoped for, there came only a shuddering blackness and ineffable loneliness; and I saw at last a fearful truth which no one had ever dared to breathe before — the unwhisperable secret of secrets — The fact that this language of stone and stridor is not a sentient perpetuation of Rust as London is of Old London and Paris of Old Paris, but that it is in fact quite unsafe, its sprawling body imperfectly embalmed and infested with queer animate things which have nothing to do with it as it was in compilation.

This book digs into all the awful details that are necessary to understand in order to write correct Unsafe Rust programs. Due to the nature of this problem, it may lead to unleashing untold horrors that shatter your psyche into a billion infinitesimal fragments of despair.

Requirements

Building the Nomicon requires mdBook. To get it:

cargo install mdbook

mdbook usage

To build the Nomicon use the build sub-command:

mdbook build

The output will be placed in the book subdirectory. To check it out, open the index.html file in your web browser. You can pass the --open flag to mdbook build and it'll open the index page in your default browser (if the process is successful) just like with cargo doc --open:

mdbook build --open

There is also a test sub-command to test all code samples contained in the book:

mdbook test

linkcheck

We use the linkcheck tool to find broken links. To run it locally:

curl -sSLo linkcheck.sh https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
sh linkcheck.sh --all nomicon

Contributing

Given that the Nomicon is still in a draft state, we'd love your help! Please feel free to open issues about anything, and send in PRs for things you'd like to fix or change. If your change is large, please open an issue first, so we can make sure that it's something we'd accept before you go through the work of getting a PR together.