mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 19:24:32 -06:00
% -> #
I forgot Rustdoc renders markdown files strangely
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
% Associated Types
|
# Associated Types
|
||||||
|
|
||||||
Associated types are a powerful part of Rust’s type system. They’re related to
|
Associated types are a powerful part of Rust’s type system. They’re related to
|
||||||
the idea of a ‘type family’, in other words, grouping multiple types together. That
|
the idea of a ‘type family’, in other words, grouping multiple types together. That
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Closures
|
# Closures
|
||||||
|
|
||||||
Sometimes it is useful to wrap up a function and _free variables_ for better
|
Sometimes it is useful to wrap up a function and _free variables_ for better
|
||||||
clarity and reuse. The free variables that can be used come from the
|
clarity and reuse. The free variables that can be used come from the
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% Conditional Compilation
|
# Conditional Compilation
|
||||||
|
|
||||||
Rust has a special attribute, `#[cfg]`, which allows you to compile code
|
Rust has a special attribute, `#[cfg]`, which allows you to compile code
|
||||||
based on a flag passed to the compiler. It has two forms:
|
based on a flag passed to the compiler. It has two forms:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% Crates and Modules
|
# Crates and Modules
|
||||||
|
|
||||||
When a project starts getting large, it’s considered good software
|
When a project starts getting large, it’s considered good software
|
||||||
engineering practice to split it up into a bunch of smaller pieces, and then
|
engineering practice to split it up into a bunch of smaller pieces, and then
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Enums
|
# Enums
|
||||||
|
|
||||||
An `enum` in Rust is a type that represents data that is one of
|
An `enum` in Rust is a type that represents data that is one of
|
||||||
several possible variants. Each variant in the `enum` can optionally
|
several possible variants. Each variant in the `enum` can optionally
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Functions
|
# Functions
|
||||||
|
|
||||||
Every Rust program has at least one function, the `main` function:
|
Every Rust program has at least one function, the `main` function:
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% if
|
# if
|
||||||
|
|
||||||
Rust’s take on `if` is not particularly complex, but it’s much more like the
|
Rust’s take on `if` is not particularly complex, but it’s much more like the
|
||||||
`if` you’ll find in a dynamically typed language than in a more traditional
|
`if` you’ll find in a dynamically typed language than in a more traditional
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Iterators
|
# Iterators
|
||||||
|
|
||||||
Let's talk about loops.
|
Let's talk about loops.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Lifetimes
|
# Lifetimes
|
||||||
|
|
||||||
This guide is three of three presenting Rust’s ownership system. This is one of
|
This guide is three of three presenting Rust’s ownership system. This is one of
|
||||||
Rust’s most unique and compelling features, with which Rust developers should
|
Rust’s most unique and compelling features, with which Rust developers should
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Loops
|
# Loops
|
||||||
|
|
||||||
Rust currently provides three approaches to performing some kind of iterative activity. They are: `loop`, `while` and `for`. Each approach has its own set of uses.
|
Rust currently provides three approaches to performing some kind of iterative activity. They are: `loop`, `while` and `for`. Each approach has its own set of uses.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Macros
|
# Macros
|
||||||
|
|
||||||
By now you’ve learned about many of the tools Rust provides for abstracting and
|
By now you’ve learned about many of the tools Rust provides for abstracting and
|
||||||
reusing code. These units of code reuse have a rich semantic structure. For
|
reusing code. These units of code reuse have a rich semantic structure. For
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Ownership
|
# Ownership
|
||||||
|
|
||||||
This guide is one of three presenting Rust’s ownership system. This is one of
|
This guide is one of three presenting Rust’s ownership system. This is one of
|
||||||
Rust’s most unique and compelling features, with which Rust developers should
|
Rust’s most unique and compelling features, with which Rust developers should
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% Primitive Types
|
# Primitive Types
|
||||||
|
|
||||||
The Rust language has a number of types that are considered ‘primitive’. This
|
The Rust language has a number of types that are considered ‘primitive’. This
|
||||||
means that they’re built-in to the language. Rust is structured in such a way
|
means that they’re built-in to the language. Rust is structured in such a way
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Raw Pointers
|
# Raw Pointers
|
||||||
|
|
||||||
Rust has a number of different smart pointer types in its standard library, but
|
Rust has a number of different smart pointer types in its standard library, but
|
||||||
there are two types that are extra-special. Much of Rust’s safety comes from
|
there are two types that are extra-special. Much of Rust’s safety comes from
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% References and Borrowing
|
# References and Borrowing
|
||||||
|
|
||||||
This guide is two of three presenting Rust’s ownership system. This is one of
|
This guide is two of three presenting Rust’s ownership system. This is one of
|
||||||
Rust’s most unique and compelling features, with which Rust developers should
|
Rust’s most unique and compelling features, with which Rust developers should
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Structs
|
# Structs
|
||||||
|
|
||||||
`struct`s are a way of creating more complex data types. For example, if we were
|
`struct`s are a way of creating more complex data types. For example, if we were
|
||||||
doing calculations involving coordinates in 2D space, we would need both an `x`
|
doing calculations involving coordinates in 2D space, we would need both an `x`
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Testing
|
# Testing
|
||||||
|
|
||||||
> Program testing can be a very effective way to show the presence of bugs, but
|
> Program testing can be a very effective way to show the presence of bugs, but
|
||||||
> it is hopelessly inadequate for showing their absence.
|
> it is hopelessly inadequate for showing their absence.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% Trait Objects
|
# Trait Objects
|
||||||
|
|
||||||
When code involves polymorphism, there needs to be a mechanism to determine
|
When code involves polymorphism, there needs to be a mechanism to determine
|
||||||
which specific version is actually run. This is called ‘dispatch’. There are
|
which specific version is actually run. This is called ‘dispatch’. There are
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Traits
|
# Traits
|
||||||
|
|
||||||
A trait is a language feature that tells the Rust compiler about
|
A trait is a language feature that tells the Rust compiler about
|
||||||
functionality a type must provide.
|
functionality a type must provide.
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Universal Function Call Syntax
|
# Universal Function Call Syntax
|
||||||
|
|
||||||
Sometimes, functions can have the same names. Consider this code:
|
Sometimes, functions can have the same names. Consider this code:
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Unsafe
|
# Unsafe
|
||||||
|
|
||||||
Rust’s main draw is its powerful static guarantees about behavior. But safety
|
Rust’s main draw is its powerful static guarantees about behavior. But safety
|
||||||
checks are conservative by nature: there are some programs that are actually
|
checks are conservative by nature: there are some programs that are actually
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% Rust Inside Other Languages
|
# Using Rust From Other Languages
|
||||||
|
|
||||||
For our third project, we’re going to choose something that shows off one of
|
For our third project, we’re going to choose something that shows off one of
|
||||||
Rust’s greatest strengths: a lack of a substantial runtime.
|
Rust’s greatest strengths: a lack of a substantial runtime.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
% Variable Bindings
|
# Variable Bindings
|
||||||
|
|
||||||
Virtually every non-'Hello World’ Rust program uses *variable bindings*. They
|
Virtually every non-'Hello World’ Rust program uses *variable bindings*. They
|
||||||
bind some value to a name, so it can be used later. `let` is
|
bind some value to a name, so it can be used later. `let` is
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
% Vectors
|
# Vectors
|
||||||
|
|
||||||
A ‘vector’ is a dynamic or ‘growable’ array, implemented as the standard
|
A ‘vector’ is a dynamic or ‘growable’ array, implemented as the standard
|
||||||
library type [`Vec<T>`][vec]. The `T` means that we can have vectors
|
library type [`Vec<T>`][vec]. The `T` means that we can have vectors
|
||||||
|
|||||||
Reference in New Issue
Block a user