diff --git a/redirects/associated-types.md b/redirects/associated-types.md index 81aae63cd8..6c259ccd25 100644 --- a/redirects/associated-types.md +++ b/redirects/associated-types.md @@ -1,11 +1,22 @@ -% There is a new edition of the book +% Associated Types -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Associated types are a way of associating a type placeholder with a trait such that the trait method definitions can use these placeholder types in their signatures. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +pub trait Iterator { + type Item; + fn next(&mut self) -> Option; +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.03 — Advanced Traits][2]** +* [In the first edition: Ch 3.30 — Associated Types][1] [1]: first-edition/associated-types.html diff --git a/redirects/attributes.md b/redirects/attributes.md index 2b32d89eff..2d7b05d065 100644 --- a/redirects/attributes.md +++ b/redirects/attributes.md @@ -1,12 +1,24 @@ -% There is a new edition of the book +% Attributes -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Any item declaration may have an attribute applied to it. -* [Index of the second edition of The Rust Programming Language][2] +```rust +// A function marked as a unit test +#[test] +fn test_foo() { + /* ... */ +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the Rust Reference: Ch 5.3 — Attributes][2]** +* [In the first edition: Ch 3.27 — Attributes][1] [1]: first-edition/attributes.html -[2]: second-edition/index.html +[2]: ../reference/attributes.html diff --git a/redirects/bibliography.md b/redirects/bibliography.md index 9f2e9dfa6d..740a26b3d3 100644 --- a/redirects/bibliography.md +++ b/redirects/bibliography.md @@ -1,12 +1,14 @@ -% There is a new edition of the book +% Bibliography -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +This page does not exist in [the second edition][2]. +You might be interested in a similar page in [the Rust Reference][3]. -* [Index of the second edition of The Rust Programming Language][2] +* **[In the Rust Reference: Appendix — Influences][3]** +* [In the first edition: Section 7 — Bibliography][1] [1]: first-edition/bibliography.html [2]: second-edition/index.html +[3]: ../reference/influences.html diff --git a/redirects/borrow-and-asref.md b/redirects/borrow-and-asref.md index 4525112ccc..2b8255bf19 100644 --- a/redirects/borrow-and-asref.md +++ b/redirects/borrow-and-asref.md @@ -1,12 +1,25 @@ -% There is a new edition of the book +% Borrow and AsRef -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> A cheap reference-to-reference conversion. +> Used to convert a value to a reference value within generic code. -* [Index of the second edition of The Rust Programming Language][2] +```rust +fn is_hello>(s: T) { + assert_eq!("hello", s.as_ref()); +} +``` + +--- + +This chapter does not exist in [the second edition][2]. +The best place to learn more about this is [the Rust documentation][3]. + +* **[In the Rust documentation: `convert::AsRef`][3]** +* [In the first edition: Ch 4.10 — Borrow and AsRef][1] [1]: first-edition/borrow-and-asref.html [2]: second-edition/index.html +[3]: ../std/convert/trait.AsRef.html diff --git a/redirects/casting-between-types.md b/redirects/casting-between-types.md index a4d901e264..7aeaf86f22 100644 --- a/redirects/casting-between-types.md +++ b/redirects/casting-between-types.md @@ -1,12 +1,32 @@ -% There is a new edition of the book +% Casting between types -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> A type cast expression is denoted with the binary operator `as`. +> Executing an `as` expression casts the value on the left-hand side to the type on the right-hand side. -* [Index of the second edition of The Rust Programming Language][2] +```rust +# fn sum(values: &[f64]) -> f64 { 0.0 } +# fn len(values: &[f64]) -> i32 { 0 } + +fn average(values: &[f64]) -> f64 { + let sum: f64 = sum(values); + let size: f64 = len(values) as f64; + sum / size +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Appendix B — Operators, section Type Cast Expressions][2]** +* [In the Rust Reference: Type Cast Expressions][3] +* [In the Rust documentation: `mem::transmute`][4] +* [In the first edition: Ch 3.29 — Casting between types][1] [1]: first-edition/casting-between-types.html -[2]: second-edition/index.html +[2]: second-edition/appendix-02-operators.html#type-cast-expressions +[3]: ../reference/expressions/operator-expr.html#type-cast-expressions +[4]: ../std/mem/fn.transmute.html \ No newline at end of file diff --git a/redirects/choosing-your-guarantees.md b/redirects/choosing-your-guarantees.md index 778891fdb6..e2205284b0 100644 --- a/redirects/choosing-your-guarantees.md +++ b/redirects/choosing-your-guarantees.md @@ -1,11 +1,21 @@ -% There is a new edition of the book +% Choosing your Guarantees -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Smart pointers are data structures that act like a pointer, but they also have additional metadata and capabilities. +> The different smart pointers defined in Rust’s standard library provide extra functionality beyond what references provide. -* [Related chapter in the second edition of The Rust Programming Language][2] +```rust +let b = Box::new(5); +println!("b = {}", b); +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 15.00 — Smart Pointers][2]** +* [In the first edition: Ch 4.8 — Choosing your Guarantees][1] [1]: first-edition/choosing-your-guarantees.html diff --git a/redirects/closures.md b/redirects/closures.md index 1f8f6aeee6..f17cbc1814 100644 --- a/redirects/closures.md +++ b/redirects/closures.md @@ -1,11 +1,27 @@ -% There is a new edition of the book +% Closures -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Anonymous functions you can save in a variable or pass as arguments to other functions. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +# use std::thread; +# use std::time::Duration; + +let expensive_closure = |num| { + println!("calculating slowly..."); + thread::sleep(Duration::from_secs(2)); + num +}; +#expensive_closure(5); +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 13.01 — Closures][2]** +* [In the first edition: Ch 3.23 — Closures][1] [1]: first-edition/closures.html diff --git a/redirects/comments.md b/redirects/comments.md index bb921f4fe3..7766940fe7 100644 --- a/redirects/comments.md +++ b/redirects/comments.md @@ -1,11 +1,22 @@ -% There is a new edition of the book +% Comments -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Comments must start with two slashes and continue until the end of the line. +> For comments that extend beyond a single line, you’ll need to include // on each line. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +// So we’re doing something complicated here, long enough that we need +// multiple lines of comments to do it! Whew! Hopefully, this comment will +// explain what’s going on. +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 3.04 — Comments][2]** +* [In the first edition: Ch 3.4 — Comments][1] [1]: first-edition/comments.html diff --git a/redirects/compiler-plugins.md b/redirects/compiler-plugins.md index f92738f4ee..fafeda3ea6 100644 --- a/redirects/compiler-plugins.md +++ b/redirects/compiler-plugins.md @@ -1,6 +1,16 @@ -% The Rust Programming Language Has Moved +% Compiler Plugins -This chapter of the book has moved to [a chapter in the Unstable -Book][unstable book plugins]. Please check it out there. +There is a new edition of the book and this is an old link. -[unstable book plugins]: ../unstable-book/language-features/plugin.html +> Compiler plugins are user-provided libraries that extend the compiler's behavior with new syntax extensions, lint checks, etc. + +--- + +This particular chapter has moved to [the Unstable Book][2]. + +* **[In the Unstable Rust Book: `plugin`][2]** +* [In the first edition: Compiler Plugins][1] (does not exist anymore) + + +[1]: first-edition/compiler-plugins.html +[2]: ../unstable-book/language-features/plugin.html diff --git a/redirects/concurrency.md b/redirects/concurrency.md index b9067cd90c..c2b96a55a3 100644 --- a/redirects/concurrency.md +++ b/redirects/concurrency.md @@ -1,11 +1,16 @@ -% There is a new edition of the book +% Concurrency -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Historically, programming [concurrency] has been difficult and error prone: Rust hopes to change that. +> Fearless concurrency allows you to write code that’s free of subtle bugs and is easy to refactor without introducing new bugs. -* [Related chapter in the second edition of The Rust Programming Language][2] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 16.00 — Fearless Concurrency][2]** +* [In the first edition: Ch 4.6 — Concurrency][1] [1]: first-edition/concurrency.html diff --git a/redirects/conditional-compilation.md b/redirects/conditional-compilation.md index b4fe83b96e..24deb11c2b 100644 --- a/redirects/conditional-compilation.md +++ b/redirects/conditional-compilation.md @@ -1,12 +1,28 @@ -% There is a new edition of the book +% Conditional Compilation -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Sometimes one wants to have different compiler outputs from the same code, depending on build target, such as targeted operating system, or to enable release builds. +> Configuration options are either provided by the compiler or passed in on the command line using. +> Rust code then checks for their presence using the `#[cfg(...)]` attribute -* [Index of the second edition of The Rust Programming Language][2] +```rust +// The function is only included in the build when compiling for macOS +#[cfg(target_os = "macos")] +fn macos_only() { + // ... +} +``` + +--- + +This particular chapter does not exist in [the second edition][2]. +The best place to learn about it is [the Rust Reference][3]. + +* **[In the Rust Reference: Ch 5.3 — Attributes, Conditional Compilation section][3]** +* [In the first edition: Ch 4.3 — Conditional Compilation][1] [1]: first-edition/conditional-compilation.html -[2]: second-edition/index.html +[2]: second-edition/ +[3]: ../reference/attributes.html#conditional-compilation diff --git a/redirects/const-and-static.md b/redirects/const-and-static.md index c8561df0da..2d7014a24f 100644 --- a/redirects/const-and-static.md +++ b/redirects/const-and-static.md @@ -1,12 +1,23 @@ -% There is a new edition of the book +% `const` and `static` -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Constants are _always_ immutable, and may only be set to a constant expression, not the result of a function call or any other value that could only be computed at runtime. +> +> Global variables are called `static` in Rust. -* [Related section about `const` in the second edition of The Rust Programming Language][2] -* [Related section about `static` in the second edition of The Rust Programming Language][3] +```rust +const MAX_POINTS: u32 = 100_000; +static HELLO_WORLD: &str = "Hello, world!"; +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 3.01 — Variables and Mutability, section Constants][2]** +* **[In the second edition: Ch 19.01 — Unsafe Rust, section Static Variables][3]** +* [In the first edition: Ch 3.26 — `const` and `static`][1] [1]: first-edition/const-and-static.html diff --git a/redirects/crates-and-modules.md b/redirects/crates-and-modules.md index 535d6ce48f..3796ed37d4 100644 --- a/redirects/crates-and-modules.md +++ b/redirects/crates-and-modules.md @@ -1,15 +1,28 @@ -% There is a new edition of the book +% Crates and Modules -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust has a module system that enables the reuse of code in an organized fashion. +> A module is a namespace that contains definitions of functions or types, and you can choose whether those definitions are visible outside their module (public) or not (private). +> +> A crate is a project that other people can pull into their projects as a dependency. -* [Related chapter about modules in the second edition of The Rust Programming Language][2] +```rust +mod network { + fn connect() { + } +} +``` -* [Related chapter about crates in the second edition of The Rust Programming Language][3] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 7.01 — `mod` and the Filesystem][2]** +* [In the second edition: Ch 14.02 — Publishing a Crate to Crates.io][2] +* [In the first edition: Ch 3.25 — Crates and Modules][1] [1]: first-edition/crates-and-modules.html -[2]: second-edition/ch07-00-modules.html -[3]: second-edition/ch14-00-more-about-cargo.html +[2]: second-edition/ch07-01-mod-and-the-filesystem.html +[3]: second-edition/ch14-02-publishing-to-crates-io.html diff --git a/redirects/deref-coercions.md b/redirects/deref-coercions.md index df927fcf80..29de95e66c 100644 --- a/redirects/deref-coercions.md +++ b/redirects/deref-coercions.md @@ -1,12 +1,30 @@ -% There is a new edition of the book +% Deref coercions -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Implementing the `Deref` trait allows us to customize the behavior of the _dereference operator_ `*`. +> By implementing `Deref` in such a way that a smart pointer can be treated like a regular reference, we can write code that operates on references and use that code with smart pointers too. -* [Related section in the second edition of The Rust Programming Language][2] +```rust +use std::ops::Deref; + +# struct MyBox(T); +impl Deref for MyBox { + type Target = T; + + fn deref(&self) -> &T { + &self.0 + } +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 15.02 — Treating Smart Pointers like Regular References with the `Deref` Trait][2]** +* [In the first edition: Ch 3.33 — Deref coercions][1] [1]: first-edition/deref-coercions.html -[2]: second-edition/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods +[2]: second-edition/ch15-02-deref.html diff --git a/redirects/documentation.md b/redirects/documentation.md index 198da596f4..64382f33c5 100644 --- a/redirects/documentation.md +++ b/redirects/documentation.md @@ -1,11 +1,31 @@ -% There is a new edition of the book +% Documentation -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Documentation comments use `///` instead of `//` and support Markdown notation for formatting the text if you’d like. +> You place documentation comments just before the item they are documenting. -* [Related section in the second edition of The Rust Programming Language][2] +```rust,no_run +/// Adds one to the number given. +/// +/// # Examples +/// +/// ``` +/// let five = 5; +/// +/// assert_eq!(6, my_crate::add_one(5)); +/// ``` +pub fn add_one(x: i32) -> i32 { + x + 1 +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 14.02 — Publishing to crates.io, section Making useful documentation][2]** +* [In the first edition: Ch 4.4 — Documentation][1] [1]: first-edition/documentation.html diff --git a/redirects/drop.md b/redirects/drop.md index 9bb7ea991b..f5f01e377e 100644 --- a/redirects/drop.md +++ b/redirects/drop.md @@ -1,11 +1,33 @@ -% There is a new edition of the book +% Drop -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> `Drop` lets us customize what happens when a value is about to go out of scope. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +struct CustomSmartPointer { + data: String, +} + +impl Drop for CustomSmartPointer { + fn drop(&mut self) { + println!("Dropping CustomSmartPointer with data `{}`!", self.data); + } +} + +fn main() { + let c = CustomSmartPointer { data: String::from("my stuff") }; + let d = CustomSmartPointer { data: String::from("other stuff") }; + println!("CustomSmartPointers created."); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 15.03 — The `Drop` Trait Runs Code on Cleanup][2]** +* [In the first edition: Ch 3.20 — Drop][1] [1]: first-edition/drop.html diff --git a/redirects/effective-rust.md b/redirects/effective-rust.md index 286f9007e9..60ca55d64b 100644 --- a/redirects/effective-rust.md +++ b/redirects/effective-rust.md @@ -1,12 +1,14 @@ -% There is a new edition of the book +% Effective Rust -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +This section does not exist in [the second edition][2]. +However, the second edition encourages writing effective Rust from the start. +It is recommended to start there. -* [Index of the second edition of The Rust Programming Language][2] +* **[The second edition of The Rust Programming Language][2]** +* [In the first edition: Ch 4 — Effective Rust][1] [1]: first-edition/effective-rust.html -[2]: second-edition/index.html +[2]: second-edition/ diff --git a/redirects/enums.md b/redirects/enums.md index 5952358ee0..9b97970909 100644 --- a/redirects/enums.md +++ b/redirects/enums.md @@ -1,11 +1,22 @@ -% There is a new edition of the book +% Enums -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Enums allow you to define a type by enumerating its possible values. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +enum IpAddrKind { + V4, + V6, +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 6.01 — Defining an Enum][2]** +* [In the first edition: Ch 3.13 — Enums][1] [1]: first-edition/enums.html diff --git a/redirects/error-handling.md b/redirects/error-handling.md index 5243e11ecd..e915657ea4 100644 --- a/redirects/error-handling.md +++ b/redirects/error-handling.md @@ -1,11 +1,15 @@ -% There is a new edition of the book +% Error Handling -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust groups errors into two major categories: _recoverable_ errors with `Result` and _unrecoverable_ errors with `panic!`. -* [Related chapter in the second edition of The Rust Programming Language][2] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 9.00 — Error Handling][2]** +* [In the first edition: Ch 4.7 — Error Handling][1] [1]: first-edition/error-handling.html diff --git a/redirects/ffi.md b/redirects/ffi.md index 0c8116ee29..1acb32b01f 100644 --- a/redirects/ffi.md +++ b/redirects/ffi.md @@ -1,12 +1,29 @@ -% There is a new edition of the book +% FFI -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Sometimes, your Rust code may need to interact with code written in another language. +> To do this, Rust has a keyword, `extern`, that facilitates creating and using a _Foreign Function Interface_ (FFI). -* [Related section in the second edition of The Rust Programming Language][2] +```rust +extern "C" { + fn abs(input: i32) -> i32; +} + +fn main() { + unsafe { + println!("Absolute value of -3 according to C: {}", abs(-3)); + } +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.01 — Unsafe Rust, section `extern` functions][2]** +* [In the first edition: Ch 4.9 — FFI][1] [1]: first-edition/ffi.html -[2]: second-edition/ch19-01-unsafe-rust.html#calling-an-unsafe-function-or-method +[2]: second-edition/ch19-01-unsafe-rust.html#extern--functions-for-calling-external-code-are-unsafe diff --git a/redirects/functions.md b/redirects/functions.md index 198a6dce14..5c61fe56b3 100644 --- a/redirects/functions.md +++ b/redirects/functions.md @@ -1,11 +1,29 @@ -% There is a new edition of the book +% Functions -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Function definitions in Rust start with `fn` and have a set of parentheses after the function name. +> The curly brackets tell the compiler where the function body begins and ends. +> We can call any function we’ve defined by entering its name followed by a set of parentheses. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +fn main() { + println!("Hello, world!"); + + another_function(); +} + +fn another_function() { + println!("Another function."); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the first edition: Ch 3.2 — Functions][1]** +* [In the second edition: Ch 3.03 — Functions][2] [1]: first-edition/functions.html diff --git a/redirects/generics.md b/redirects/generics.md index 333a979caf..8e52802dfa 100644 --- a/redirects/generics.md +++ b/redirects/generics.md @@ -1,11 +1,28 @@ -% There is a new edition of the book +% Generics -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Generics are abstract stand-ins for concrete types or other properties. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +struct Point { + x: T, + y: U, +} + +fn main() { + let both_integer = Point { x: 5, y: 10 }; + let both_float = Point { x: 1.0, y: 4.0 }; + let integer_and_float = Point { x: 5, y: 4.0 }; +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 10.00 — Generic Types, Traits, and Lifetimes][2]** +* [In the first edition: Ch 3.18 — Generics][1] [1]: first-edition/generics.html diff --git a/redirects/getting-started.md b/redirects/getting-started.md index 0b8296a0ab..168927c25a 100644 --- a/redirects/getting-started.md +++ b/redirects/getting-started.md @@ -1,11 +1,12 @@ -% There is a new edition of the book +% Getting Started -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +You can [continue to the exact older page][1]. +If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. -* [Related chapter in the second edition of The Rust Programming Language][2] +* **[In the second edition: Introduction][2]** +* [In the first edition: Getting Started][1] [1]: first-edition/getting-started.html diff --git a/redirects/glossary.md b/redirects/glossary.md index b044d2083f..c0fd384abd 100644 --- a/redirects/glossary.md +++ b/redirects/glossary.md @@ -1,12 +1,14 @@ -% There is a new edition of the book +% Glossary -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +This section does not exist in [the second edition][2]. +However, the second edition defines the terms it uses inline, rather than using a glossary. +It is recommended to start there. -* [Index of the second edition of The Rust Programming Language][2] +* **[The second edition of The Rust Programming Language][2]** +* [In the first edition: Glossary][1] [1]: first-edition/glossary.html -[2]: second-edition/index.html +[2]: second-edition/ diff --git a/redirects/guessing-game.md b/redirects/guessing-game.md index dd31e0829e..3a243dd4b8 100644 --- a/redirects/guessing-game.md +++ b/redirects/guessing-game.md @@ -1,11 +1,11 @@ -% There is a new edition of the book +% Tutorial: Guessing Game -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. -* [Related chapter in second edition of The Rust Programming Language][2] +* **[In the first edition: Tutorial — Guessing Game][1]** +* [In the second edition: Ch 2.00 — Guessing Game tutorial][2] [1]: first-edition/guessing-game.html diff --git a/redirects/if-let.md b/redirects/if-let.md index 78de04ca7b..95da06a455 100644 --- a/redirects/if-let.md +++ b/redirects/if-let.md @@ -1,11 +1,22 @@ -% There is a new edition of the book +% if let -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> The `if let` syntax lets you combine `if` and `let` into a less verbose way to handle values that match one pattern and ignore the rest. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +let some_u8_value = Some(3u8); +if let Some(3) = some_u8_value { + println!("three"); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 6.03 — Concise Control Flow with `if let`][2]** +* [In the first edition: Ch 3.21 — if let][1] [1]: first-edition/if-let.html diff --git a/redirects/if.md b/redirects/if.md index dafc42f7c2..cf933a44d0 100644 --- a/redirects/if.md +++ b/redirects/if.md @@ -1,11 +1,27 @@ -% There is a new edition of the book +% if -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> An `if` expression allows us to branch our code depending on conditions. -* [Related section in second edition of The Rust Programming Language][2] +```rust +fn main() { + let number = 3; + + if number < 5 { + println!("condition was true"); + } else { + println!("condition was false"); + } +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 3.05 — Control flow][2]** +* [In the first edition: Ch 3.5 — if][1] [1]: first-edition/if.html diff --git a/redirects/iterators.md b/redirects/iterators.md index 8df24a17e2..03c7134126 100644 --- a/redirects/iterators.md +++ b/redirects/iterators.md @@ -1,11 +1,26 @@ -% There is a new edition of the book +% Iterators -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> The iterator pattern allows you to perform some task on a sequence of items in turn. +> An iterator is responsible for the logic of iterating over each item and determining when the sequence has finished. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +let v1 = vec![1, 2, 3]; + +let v1_iter = v1.iter(); + +for val in v1_iter { + println!("Got: {}", val); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 13.02 — Iterators][2]** +* [In the first edition: Ch 4.5 — Iterators][1] [1]: first-edition/iterators.html diff --git a/redirects/lifetimes.md b/redirects/lifetimes.md index 482ef64433..e9a5492719 100644 --- a/redirects/lifetimes.md +++ b/redirects/lifetimes.md @@ -1,13 +1,28 @@ -% There is a new edition of the book +% Lifetimes -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Every reference in Rust has a lifetime, which is the scope for which that reference is valid. +> Most of the time lifetimes are implicit and inferred. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +{ + let x = 5; // -----+-- 'b + // | + let r = &x; // --+--+-- 'a + // | | + println!("r: {}", r); // | | + // --+ | +} // -----+ +``` -* [Related page in the second edition of The Rust Programming Language (covering more advanced topics)][3] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 10.03 — Lifetimes][2]** +* [In the second edition: Ch 19.02 — Advanced Lifetimes][3] +* [In the first edition: Ch 3.10 — Lifetimes][1] [1]: first-edition/lifetimes.html diff --git a/redirects/loops.md b/redirects/loops.md index 4c7c6d9d5d..cabe918b4b 100644 --- a/redirects/loops.md +++ b/redirects/loops.md @@ -1,11 +1,35 @@ -% There is a new edition of the book +% Loops -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust has three kinds of loops: `loop`, `while`, and `for`. +> The `loop` keyword tells Rust to execute a block of code over and over again forever or until you explicitly tell it to stop. +> `while` loops evaluate a block of code until a condition ceases to be true. +> A `for` loop executes some code for each item in a collection. -* [Related section in the second edition of The Rust Programming Language][2] +```rust,no_run +loop { + println!("again!"); +} + +let mut number = 3; +while number != 0 { + println!("{}!", number); + number = number - 1; +} + +let a = [10, 20, 30, 40, 50]; +for element in a.iter() { + println!("the value is: {}", element); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 3.05 — Control flow][2]** +* [In the first edition: Ch 3.6 — Loops][1] [1]: first-edition/loops.html diff --git a/redirects/macros.md b/redirects/macros.md index 42a21c9457..d1f7369b9e 100644 --- a/redirects/macros.md +++ b/redirects/macros.md @@ -1,12 +1,31 @@ -% There is a new edition of the book +% Macros -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> While functions and types abstract over code, macros abstract at a syntactic level. -* [Index of the second edition of The Rust Programming Language][2] +```rust +macro_rules! five_times { + ($x:expr) => (5 * $x); +} + +fn main() { + assert_eq!(25, five_times!(2 + 3)); +} +``` + +--- + +This chapter does not exist yet in [the second edition][2]. +You can check out other resources that describe macros. + +* **[Rust By Example: Macros][3]** +* [In the Rust Reference: Ch 3.1 — Macros by Example][4] +* [In the second edition: (future) Appendix E — Macros][2] +* [In the first edition: Ch 3.34 — Macros][1] [1]: first-edition/macros.html -[2]: second-edition/index.html +[2]: second-edition/appendix-05-macros.html +[3]: https://rustbyexample.com/macros.html +[4]: ../reference/macros-by-example.html \ No newline at end of file diff --git a/redirects/match.md b/redirects/match.md index 244617b5d6..5a32215ab4 100644 --- a/redirects/match.md +++ b/redirects/match.md @@ -1,13 +1,35 @@ -% There is a new edition of the book +% Match -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> `match` allows us to compare a value against a series of patterns and then execute code based on which pattern matches. +> Patterns can be made up of literal values, variable names, wildcards, and many other things. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +enum Coin { + Penny, + Nickel, + Dime, + Quarter, +} -* [Related chapter in the second edition of The Rust Programming Language (covering more advanced topics)][3] +fn value_in_cents(coin: Coin) -> u32 { + match coin { + Coin::Penny => 1, + Coin::Nickel => 5, + Coin::Dime => 10, + Coin::Quarter => 25, + } +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 6.02 — The `match` Control Flow Operator][2]** +* [In the second edition: Ch 18.00 — Patterns][3] +* [In the first edition: Ch 3.14 — Match][1] [1]: first-edition/match.html diff --git a/redirects/method-syntax.md b/redirects/method-syntax.md index c320c97201..a842c9badb 100644 --- a/redirects/method-syntax.md +++ b/redirects/method-syntax.md @@ -1,11 +1,28 @@ -% There is a new edition of the book +% Method Syntax -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Methods are different from functions in that they’re defined within the context of a struct, and their first parameter is always `self`, which represents the instance of the struct the method is being called on. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +# struct Rectangle { +# width: u32, +# height: u32, +# } + +impl Rectangle { + fn area(&self) -> u32 { + self.width * self.height + } +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 5.03 — Method Syntax][2]** +* [In the first edition: Ch 3.16 — Method Syntax][1] [1]: first-edition/method-syntax.html diff --git a/redirects/mutability.md b/redirects/mutability.md index 754a6b2310..6f48bc3065 100644 --- a/redirects/mutability.md +++ b/redirects/mutability.md @@ -1,11 +1,22 @@ -% There is a new edition of the book +% Mutability -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Variables are immutable only by default; we can make them mutable by adding mut in front of the variable name. -* [Related page in second edition of The Rust Programming Language][2] +```rust +let mut x = 5; +println!("The value of x is: {}", x); +x = 6; +println!("The value of x is: {}", x); +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 3.01 — Variables and Mutability][2]** +* [In the first edition: Ch 3.11 — Mutability][1] [1]: first-edition/mutability.html diff --git a/redirects/operators-and-overloading.md b/redirects/operators-and-overloading.md index 06a68dadfb..6cb8899b52 100644 --- a/redirects/operators-and-overloading.md +++ b/redirects/operators-and-overloading.md @@ -1,12 +1,43 @@ -% There is a new edition of the book +% Operators and Overloading -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust does not allow you to create your own operators or overload arbitrary operators, but the operations and corresponding traits listed in `std::ops` can be overloaded by implementing the traits associated with the operator. -* [Related section in the second edition of The Rust Programming Language][2] +```rust +use std::ops::Add; +#[derive(Debug,PartialEq)] +struct Point { + x: i32, + y: i32, +} + +impl Add for Point { + type Output = Point; + + fn add(self, other: Point) -> Point { + Point { + x: self.x + other.x, + y: self.y + other.y, + } + } +} + +fn main() { + assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, + Point { x: 3, y: 3 }); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.03 — Advanced Traits, section Operator Overloading][2]** +* [In the Rust documentation: `std::ops`][3] +* [In the first edition: Ch 3.32 — Operators and Overloading][1] [1]: first-edition/operators-and-overloading.html [2]: second-edition/ch19-03-advanced-traits.html#operator-overloading-and-default-type-parameters +[3]: ../std/ops/ diff --git a/redirects/ownership.md b/redirects/ownership.md index 1b7e0eb992..adca776217 100644 --- a/redirects/ownership.md +++ b/redirects/ownership.md @@ -1,11 +1,19 @@ -% There is a new edition of the book +% Ownership -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Ownership is Rust’s most unique feature, and it enables Rust to make memory safety guarantees without needing a garbage collector. +> +> 1. Each value in Rust has a variable that’s called its _owner_. +> 2. There can only be one owner at a time. +> 3. When the owner goes out of scope, the value will be dropped. -* [Related chapter in the second edition of The Rust Programming Language][2] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 4.00 — Understanding Ownership][2]** +* [In the first edition: Ch 3.8 — Ownership][1] [1]: first-edition/ownership.html diff --git a/redirects/patterns.md b/redirects/patterns.md index 6bdbbfacfe..4044f16ab6 100644 --- a/redirects/patterns.md +++ b/redirects/patterns.md @@ -1,15 +1,31 @@ -% There is a new edition of the book +% Patterns -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Patterns are a special syntax within Rust for matching against the structure of our types, complex or simple. +> A pattern is made up of some combination of literals; destructured arrays, enums, structs, or tuples; variables, wildcards, and placeholders. +> These pieces describe the “shape” of the data we’re working with. -* [Related section in the second edition of The Rust Programming Language][2] +```rust +let x = Some(5); +let y = 10; -* [Related page in the second edition of The Rust Programming Language (covering more advanced topics)][3] +match x { + Some(50) => println!("Got 50"), + Some(y) => println!("Matched, y = {:?}", y), + _ => println!("Default case, x = {:?}", x), +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 18.03 — Patterns][2]** +* [In the second edition: Ch 6.02 — Match][3] +* [In the first edition: Ch 3.15 — Patterns][1] [1]: first-edition/patterns.html -[2]: second-edition/ch06-02-match.html#patterns-that-bind-to-values -[3]: second-edition/ch18-03-pattern-syntax.html +[2]: second-edition/ch18-00-patterns.html +[3]: second-edition/ch06-02-match.html#patterns-that-bind-to-values diff --git a/redirects/primitive-types.md b/redirects/primitive-types.md index 76f5f6c279..7244fbaa60 100644 --- a/redirects/primitive-types.md +++ b/redirects/primitive-types.md @@ -1,11 +1,23 @@ -% There is a new edition of the book +% Primitive Types -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust is a _statically typed_ language, which means that it must know the types of all variables at compile time. +> The compiler can usually infer what type we want to use based on the value and how we use it. +> In cases when many types are possible, a _type annotation_ must be added. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +let x = 2.0; // f64 + +let y: f32 = 3.0; // f32 +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 3.02 — Data Types][2]** +* [In the first edition: Ch 3.3 — Primitive Types][1] [1]: first-edition/primitive-types.html diff --git a/redirects/procedural-macros.md b/redirects/procedural-macros.md index 823efca6e8..66a7d463e2 100644 --- a/redirects/procedural-macros.md +++ b/redirects/procedural-macros.md @@ -1,13 +1,21 @@ -% There is a new edition of the book +% Procedural Macros (and custom Derive) -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Procedural macros allow for all sorts of advanced metaprogramming in Rust. -* [Index of the second edition of The Rust Programming Language][2] +--- +This chapter does not exist yet in [the second edition][2]. +You can check out other resources that describe macros. + +* **[In the Rust Reference: Ch 3.2 — Procedural Macros][4]** +* [The `proc_macro` crate documentation][3] +* [In the second edition: (future) Appendix E — Macros][2] +* [In the first edition: Ch 4.13 — Procedural Macros (and custom Derive)][1] [1]: first-edition/procedural-macros.html -[2]: second-edition/index.html +[2]: second-edition/appendix-05-macros.html +[3]: ../stable/proc_macro/index.html +[4]: ../reference/procedural-macros.html \ No newline at end of file diff --git a/redirects/raw-pointers.md b/redirects/raw-pointers.md index c9259fd2ba..08a6900d79 100644 --- a/redirects/raw-pointers.md +++ b/redirects/raw-pointers.md @@ -1,11 +1,22 @@ -% There is a new edition of the book +% Raw Pointers -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Raw pointers are allowed to ignore many of the rules that references have to follow. -* [Related section in the second edition of The Rust Programming Language][2] +```rust +let mut num = 5; + +let r1 = &num as *const i32; +let r2 = &mut num as *mut i32; +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.01 — Unsafe Rust, section Dereferencing a Raw Pointer][2]** +* [In the first edition: Ch 3.35 — Raw Pointers][1] [1]: first-edition/raw-pointers.html diff --git a/redirects/references-and-borrowing.md b/redirects/references-and-borrowing.md index 2dc1f113c0..c3e29d671e 100644 --- a/redirects/references-and-borrowing.md +++ b/redirects/references-and-borrowing.md @@ -1,11 +1,23 @@ -% There is a new edition of the book +% References and Borrowing -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> A reference _refers_ to a value but does not own it. +> Because it does not own it, the value it points to will not be dropped when the reference goes out of scope. -* [Related page in second edition of The Rust Programming Language][2] +```rust +fn calculate_length(s: &String) -> usize { // s is a reference to a String + s.len() +} // Here, s goes out of scope. But because it does not have ownership of what + // it refers to, nothing happens. +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 4.02 — References and Borrowing][2]** +* [In the first edition: Ch 3.9 — References and Borrowing][1] [1]: first-edition/references-and-borrowing.html diff --git a/redirects/release-channels.md b/redirects/release-channels.md index ce4af005be..8c209e0e60 100644 --- a/redirects/release-channels.md +++ b/redirects/release-channels.md @@ -1,12 +1,28 @@ -% There is a new edition of the book +% Release Channels -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> The Rust project uses a concept called ‘release channels’ to manage releases. +> New nightly releases are created once a day. +> Every six weeks, the latest nightly release is promoted to ‘Beta’. +> At that point, it will only receive patches to fix serious errors. +> Six weeks later, the beta is promoted to ‘Stable’. -* [Index of the second edition of The Rust Programming Language][2] +--- + +This chapter does not exist yet in [the second edition][2]. +You can check out other resources that describe release channels. + +* **[In the Rustup documentation: Keeping Rust Up-to-date][4]** +* [On the website: Install Rust][5] +* [In the Rust RFCs: RFC 507 — Release Channels][3] +* [In the second edition: (future) Appendix D — Nightly Rust][2] +* [In the first edition: Ch 4.11 — Release Channels][1] [1]: first-edition/release-channels.html -[2]: second-edition/index.html +[2]: second-edition/appendix-04-nightly-rust.html +[3]: https://github.com/rust-lang/rfcs/blob/master/text/0507-release-channels.md +[4]: https://github.com/rust-lang-nursery/rustup.rs/blob/master/README.md#keeping-rust-up-to-date +[5]: https://www.rust-lang.org/en-US/install.html + diff --git a/redirects/strings.md b/redirects/strings.md index 8aaaab51eb..2e50d9d88c 100644 --- a/redirects/strings.md +++ b/redirects/strings.md @@ -1,16 +1,29 @@ -% There is a new edition of the book +% Strings -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> A `String` is allocated on the heap and as such is able to store an amount of text that is unknown to us at compile time. +> You can create a `String` from a string literal using the `from` function. +> A _string slice_ is a reference to part of a `String`. -* [Related section in second edition of The Rust Programming Language][2] +```rust +let s = String::from("hello world"); -* [Related page in second edition of The Rust Programming Language (covering more advanced topics)][3] +let hello = &s[0..5]; +let world = &s[6..11]; +``` +--- -[1]: first-edition/strings.html -[2]: second-edition/ch04-03-slices.html#string-slices -[3]: second-edition/ch08-02-strings.html +Here are the relevant sections in the new and old books: + +* **[In second edition: Ch 8.02 — Strings][2]** +* [In second edition: Ch 4.01 — Ownership, section The String Type][3] +* [In second edition: Ch 4.03 — Slices, section String Slices][4] +* [In the first edition: Ch 3.17 — Strings][1] + +[1]: first-edition/strings.html +[2]: second-edition/ch08-02-strings.html +[3]: second-edition/ch04-01-what-is-ownership.html#the-string-type +[4]: second-edition/ch04-03-slices.html#string-slices diff --git a/redirects/structs.md b/redirects/structs.md index 4325281ce1..eb18820476 100644 --- a/redirects/structs.md +++ b/redirects/structs.md @@ -1,11 +1,24 @@ -% There is a new edition of the book +% Structs -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> A _struct_ is a custom data type that lets us name and package together multiple related values that make up a meaningful group. -* [Related chapter in second edition of The Rust Programming Language][2] +```rust +struct User { + username: String, + email: String, + sign_in_count: u64, + active: bool, +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In second edition: Ch 5.00 — Structs][2]** +* [In the first edition: Ch 3.12 — Structs][1] [1]: first-edition/structs.html diff --git a/redirects/syntax-and-semantics.md b/redirects/syntax-and-semantics.md index 666d1c1488..293f694fac 100644 --- a/redirects/syntax-and-semantics.md +++ b/redirects/syntax-and-semantics.md @@ -1,13 +1,14 @@ -% There is a new edition of the book +% Syntax and Semantics -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +Here are the relevant sections in the new and old books: -* [Related chapter in the second edition of The Rust Programming Language (covering Rust syntax in general)][2] -* [Related page in the second edition of The Rust Programming Language (covering Rust keywords)][3] -* [Related page in the second edition of The Rust Programming Language (covering Rust operators)][4] + +* **[In the second edition: Ch 3.00 — Common Programming Concepts][2]** +* [In the second edition: Appendix A — Keywords][3] +* [In the second edition: Appendix B — Operators][4] +* [In the first edition: Ch 3 — Syntax and Semantics][1] [1]: first-edition/syntax-and-semantics.html diff --git a/redirects/syntax-index.md b/redirects/syntax-index.md index 1a429505e2..cd03b67205 100644 --- a/redirects/syntax-index.md +++ b/redirects/syntax-index.md @@ -1,12 +1,14 @@ -% There is a new edition of the book +% Syntax Index -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +Here are the relevant sections in the new and old books: -* [Index of the second edition of The Rust Programming Language][2] +* **[In the second edition: Appendix A — Keywords][2]** +* **[In the second edition: Appendix B — Operators][3]** +* [In the first edition: Ch 6 — Syntax Index][1] [1]: first-edition/syntax-index.html -[2]: second-edition/index.html +[2]: second-edition/appendix-01-keywords.html +[3]: second-edition/appendix-02-operators.html diff --git a/redirects/testing.md b/redirects/testing.md index 0d6a0be75c..79b325b8ed 100644 --- a/redirects/testing.md +++ b/redirects/testing.md @@ -1,11 +1,24 @@ -% There is a new edition of the book +% Testing -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust includes support for writing software tests within the language itself. -* [Related chapter in the second edition of The Rust Programming Language][2] +```rust +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + } +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 11.00 — Testing][2]** +* [In the first edition: Ch 4.2 — Testing][1] [1]: first-edition/testing.html diff --git a/redirects/the-stack-and-the-heap.md b/redirects/the-stack-and-the-heap.md index 4986aa8a5a..59938b6bf9 100644 --- a/redirects/the-stack-and-the-heap.md +++ b/redirects/the-stack-and-the-heap.md @@ -1,11 +1,18 @@ -% There is a new edition of the book +% The Stack and the Heap -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Both the stack and the heap are parts of memory that is available to your code to use at runtime, but they are structured in different ways. +> The stack stores values in the order it gets them and removes the values in the opposite order. +> All data on the stack must take up a known, fixed size. +> For data with a size unknown to us at compile time or a size that might change, we can store data on the heap instead. -* [Related section in the second edition of The Rust Programming Language][2] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 4.01 — What is Ownership, section The Stack and the Heap][2]** +* [In the first edition: Ch 4.1 — The Stack and the Heap][1] [1]: first-edition/the-stack-and-the-heap.html diff --git a/redirects/trait-objects.md b/redirects/trait-objects.md index 64e05d6b48..fb4a5b272b 100644 --- a/redirects/trait-objects.md +++ b/redirects/trait-objects.md @@ -1,11 +1,67 @@ -% There is a new edition of the book +% Trait Objects -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Trait objects combine the data made up of the pointer to a concrete object with the behavior of the methods defined in the trait. +> A trait defines behavior that we need in a given situation. +> We can then use a trait as a trait object in places where we would use a concrete type or a generic type. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +pub struct InputBox { + pub label: String, +} + +impl Draw for InputBox { + fn draw(&self) { + // Code to actually draw an input box + } +} + +pub struct Button { + pub label: String, +} + +impl Draw for Button { + fn draw(&self) { + // Code to actually draw a button + } +} + +pub struct Screen { + pub components: Vec, +} + +impl Screen + where T: Draw { + pub fn run(&self) { + for component in self.components.iter() { + component.draw(); + } + } +} + +fn main() { + let screen = Screen { + components: vec![ + Box::new(InputBox { + label: String::from("OK"), + }), + Box::new(Button { + label: String::from("OK"), + }), + ], + }; + + screen.run(); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 17.02 — Trait Objects][2]** +* [In the first edition: Ch 3.22 — Trait Objects][1] [1]: first-edition/trait-objects.html diff --git a/redirects/traits.md b/redirects/traits.md index 469f5c574a..baffad4a43 100644 --- a/redirects/traits.md +++ b/redirects/traits.md @@ -1,13 +1,22 @@ -% There is a new edition of the book +% Traits -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Traits abstract over behavior that types can have in common. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +pub trait Summarizable { + fn summary(&self) -> String; +} +``` -* [Related page in the second edition of The Rust Programming Language (covering more advanced topics)][3] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 10.02 — Traits][2]** +* [In the second edition: Ch 19.03 — Advanced Traits][3] +* [In the first edition: Ch 3.19 — Traits][1] [1]: first-edition/traits.html diff --git a/redirects/type-aliases.md b/redirects/type-aliases.md index 79eb5527bd..33e9f1faf7 100644 --- a/redirects/type-aliases.md +++ b/redirects/type-aliases.md @@ -1,11 +1,19 @@ -% There is a new edition of the book +% `type` aliases -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust provides the ability to declare a _type alias_ with the `type` keyword to give an existing type another name. -* [Related section in the second edition of The Rust Programming Language][2] +```rust +type Kilometers = i32; +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.04 — Advanced Types, section Type Synonyms][2]** +* [In the first edition: Ch 3.28 — `type` aliases][1] [1]: first-edition/type-aliases.html diff --git a/redirects/ufcs.md b/redirects/ufcs.md index 87438a1a38..1d530ca179 100644 --- a/redirects/ufcs.md +++ b/redirects/ufcs.md @@ -1,11 +1,53 @@ -% There is a new edition of the book +% Universal Function Call Syntax -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust cannot prevent a trait from having a method with the same name as another trait’s method, nor can it prevent us from implementing both of these traits on one type. +> In order to be able to call each of the methods with the same name, then, we need to tell Rust which one we want to use. -* [Related section in the second edition of The Rust Programming Language][2] +```rust +trait Pilot { + fn fly(&self); +} + +trait Wizard { + fn fly(&self); +} + +struct Human; + +impl Pilot for Human { +# fn fly(&self) { +# println!("This is your captain speaking."); +# } +} + +impl Wizard for Human { +# fn fly(&self) { +# println!("Up!"); +# } +} + +impl Human { +# fn fly(&self) { +# println!("*waving arms furiously*"); +# } +} + +fn main() { + let person = Human; + Pilot::fly(&person); + Wizard::fly(&person); + person.fly(); +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.03 — Advanced Traits, section Fully Qualified Syntax][2]** +* [In the first edition: Ch 3.24 — Universal Function Call Syntax][1] [1]: first-edition/ufcs.html diff --git a/redirects/unsafe.md b/redirects/unsafe.md index e8e5a03479..c14b414234 100644 --- a/redirects/unsafe.md +++ b/redirects/unsafe.md @@ -1,12 +1,18 @@ -% There is a new edition of the book +% `unsafe` -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust has a second language hiding out inside of it, unsafe Rust, which does not enforce memory safety guarantees. -* [Related page in the second edition of The Rust Programming Language][2] +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.01 — Unsafe Rust][2]** +* [The Rustonomicon, The Dark Arts of Advanced and Unsafe Rust Programming][3] +* [In the first edition: Ch 3.36 — `unsafe`][1] [1]: first-edition/unsafe.html [2]: second-edition/ch19-01-unsafe-rust.html +[3]: ../nomicon/ diff --git a/redirects/unsized-types.md b/redirects/unsized-types.md index 05ac4100ad..d209c0d3bc 100644 --- a/redirects/unsized-types.md +++ b/redirects/unsized-types.md @@ -1,11 +1,23 @@ -% There is a new edition of the book +% Unsized Types -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Sometimes referred to as ‘DSTs’ or ‘unsized types’, these types let us talk about types whose size we can only know at runtime. +> The `Sized` trait is automatically implemented for everything the compiler knows the size of at compile time. +> A trait bound on `?Sized` is the opposite of a trait bound on `Sized`; that is, we would read this as “`T` may or may not be `Sized`”. -* [Related section in the second edition of The Rust Programming Language][2] +```rust,ignore +fn generic(t: &T) { + // ...snip... +} +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 19.04 — Advanced Types, section Dynamically Sized Types][2]** +* [In the first edition: Ch 3.31 — Unsized Types][1] [1]: first-edition/unsized-types.html diff --git a/redirects/using-rust-without-the-standard-library.md b/redirects/using-rust-without-the-standard-library.md index fd5c29967f..06deb6ee46 100644 --- a/redirects/using-rust-without-the-standard-library.md +++ b/redirects/using-rust-without-the-standard-library.md @@ -1,12 +1,17 @@ -% There is a new edition of the book +% Using Rust without the Standard Library -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Rust’s standard library provides a lot of useful functionality, but assumes support for various features of its host system: threads, networking, heap allocation, and others. +> There are systems that do not have these features, however. -* [Index of the second edition of The Rust Programming Language][2] +--- + +This particular chapter has moved to [the Unstable Book][2]. + +* **[In the Unstable Rust Book: `lang_items` — Writing an executable without stdlib][2]** +* [In the first edition: Ch 4.12 — Using Rust without the Standard Library][1] [1]: first-edition/using-rust-without-the-standard-library.html -[2]: second-edition/index.html +[2]: ../unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib diff --git a/redirects/variable-bindings.md b/redirects/variable-bindings.md index 7476d63505..fcafa7e2af 100644 --- a/redirects/variable-bindings.md +++ b/redirects/variable-bindings.md @@ -1,12 +1,20 @@ -% There is a new edition of the book +% Variable Bindings -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Variable bindings bind some value to a name, so it can be used later. -* [Index of the second edition of The Rust Programming Language][2] +```rust +let foo = 5; +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 2.00 — Guessing Game Tutorial, section Variables][2]** +* [In the first edition: Ch 3.1 — Variable Bindings][1] [1]: first-edition/variable-bindings.html -[2]: second-edition/index.html +[2]: second-edition/ch02-00-guessing-game-tutorial.html#storing-values-with-variables diff --git a/redirects/vectors.md b/redirects/vectors.md index bf2ad1c01a..ac05844842 100644 --- a/redirects/vectors.md +++ b/redirects/vectors.md @@ -1,11 +1,21 @@ -% There is a new edition of the book +% Vectors -This is an old link. You can [continue to the exact older page][1]. -If you're trying to learn Rust, checking out [the second edition][2] might be a better choice. +There is a new edition of the book and this is an old link. -* [This page in the first edition of the The Rust Programming Language][1] +> Vectors store more than one value in a single data structure that puts all the values next to each other in memory. +> Vectors can only store values of the same type. -* [Related page in the second edition of The Rust Programming Language][2] +```rust +let v: Vec = Vec::new(); +let numbers = vec![1, 2, 3]; +``` + +--- + +Here are the relevant sections in the new and old books: + +* **[In the second edition: Ch 8.01 — Vectors][2]** +* [In the first edition: Ch 3.7 — Vectors][1] [1]: first-edition/vectors.html