doc.rust-lang.org
Inline assembly Support for inline assembly is provided via the asm!, naked_asm!, and global_asm! macros. It can be used to embed handwritten assembly in the assembly output generated by the compiler. Support for inline assembly is stable o...
The Rust Reference
Book
2024-01-01
~56 min read
doc.rust-lang.org
Linkage [!NOTE] This section is described more in terms of the compiler than of the language. The compiler supports various methods to link crates together both statically and dynamically. This section will explore the various methods to li...
The Rust Reference
Book
2024-01-01
~10 min read
doc.rust-lang.org
Panic Rust provides a mechanism to prevent a function from returning normally, and instead "panic," which is a response to an error condition that is typically not expected to be recoverable within the context in which the error is encounte...
The Rust Reference
Book
2024-01-01
~4 min read
doc.rust-lang.org
Variables A variable is a component of a stack frame, either a named function parameter, an anonymous temporary, or a named local variable. A local variable (or stack-local allocation) holds a value directly, allocated within the stack's me...
The Rust Reference
Book
2024-01-01
~1 min read
doc.rust-lang.org
Memory allocation and lifetime The items of a program are those functions, modules, and types that have their value calculated at compile-time and stored uniquely in the memory image of the rust process. Items are neither dynamically alloca...
The Rust Reference
Book
2024-01-01
~1 min read
doc.rust-lang.org
Memory model [!WARNING] The memory model of Rust is incomplete and not fully decided. Bytes The most basic unit of memory in Rust is a byte. [!NOTE] While bytes are typically lowered to hardware bytes, Rust uses an "abstract" notion of byte...
The Rust Reference
Book
2024-01-01
~1 min read
doc.rust-lang.org
Visibility and privacy Visibility -> `pub` | `pub` `(` `crate` `)` | `pub` `(` `self` `)` | `pub` `(` `super` `)` | `pub` `(` `in` SimplePath `)` These two terms are often used interchangeably, and what they are attempting to convey is the...
The Rust Reference
Book
2024-01-01
~7 min read
doc.rust-lang.org
Name resolution Name resolution is the process of tying paths and other identifiers to the declarations of those entities. Names are segregated into different namespaces, allowing entities in different namespaces to share the same name with...
The Rust Reference
Book
2024-01-01
~11 min read
doc.rust-lang.org
Paths A path is a sequence of one or more path segments separated by :: tokens. Paths are used to refer to items, values, types, macros, and attributes. Two examples of simple paths consisting of only identifier segments: x; x::y::z; Types...
The Rust Reference
Book
2024-01-01
~9 min read
doc.rust-lang.org
Preludes A prelude is a collection of names that are automatically brought into scope of every module in a crate. These prelude names are not part of the module itself: they are implicitly queried during name resolution. For example, even t...
The Rust Reference
Book
2024-01-01
~5 min read
doc.rust-lang.org
Scopes A scope is the region of source text where a named entity may be referenced with that name. The following sections provide details on the scoping rules and behavior, which depend on the kind of entity and where it is declared. The pr...
The Rust Reference
Book
2024-01-01
~8 min read
doc.rust-lang.org
Namespaces A namespace is a logical grouping of declared names. Names are segregated into separate namespaces based on the kind of entity the name refers to. Namespaces allow the occurrence of a name in one namespace to not conflict with th...
The Rust Reference
Book
2024-01-01
~3 min read
doc.rust-lang.org
Names An entity is a language construct that can be referred to in some way within the source program, usually via a path. Entities include types, items, generic parameters, variable bindings, loop labels, lifetimes, fields, attributes, and...
The Rust Reference
Book
2024-01-01
~2 min read
doc.rust-lang.org
Special types and traits Certain types and traits that exist in the standard library are known to the Rust compiler. This chapter documents the special features of these types and traits. Box<T> [Box<T>] has a few special features that Rust...
The Rust Reference
Book
2024-01-01
~4 min read
doc.rust-lang.org
Lifetime elision Rust has rules that allow lifetimes to be elided in various places where the compiler can infer a sensible default choice. Lifetime elision in functions In order to make common patterns more ergonomic, lifetime arguments ca...
The Rust Reference
Book
2024-01-01
~5 min read
doc.rust-lang.org
Destructors When an initialized variable or temporary goes out of scope, its destructor is run or it is dropped. Assignment also runs the destructor of its left-hand operand, if it's initialized. If a variable has been partially initialized...
The Rust Reference
Book
2024-01-01
~16 min read
doc.rust-lang.org
Divergence A diverging expression is an expression that never completes normal execution. fn diverges() -> ! { panic!("This function never returns!"); } fn example() { let x: i32 = diverges(); // This line never completes. println!("This is...
The Rust Reference
Book
2024-01-01
~1 min read
doc.rust-lang.org
Type coercions Type coercions are implicit operations that change the type of a value. They happen automatically at specific locations and are highly restricted in what types actually coerce. Any conversions allowed by coercion can also be...
The Rust Reference
Book
2024-01-01
~7 min read
doc.rust-lang.org
Trait and lifetime bounds Bounds -> Bound ( `+` Bound )* `+`? Bound -> Lifetime | TraitBound | UseBound TraitBound -> ( `?` | ForLifetimes )? TypePath | `(` ( `?` | ForLifetimes )? TypePath `)` LifetimeBounds -> ( Lifetime `+` )* Lifetime?...
The Rust Reference
Book
2024-01-01
~5 min read
doc.rust-lang.org
Subtyping and variance Subtyping is implicit and can occur at any stage in type checking or inference. Subtyping is restricted to two cases: variance with respect to lifetimes and between types with higher ranked lifetimes. If we were to er...
The Rust Reference
Book
2024-01-01
~3 min read