book/redirects/generics.md

31 lines
693 B
Markdown
Raw Permalink Normal View History

% Generics
2017-03-03 14:50:30 +00:00
<small>There is a new edition of the book and this is an old link.</small>
> Generics are abstract stand-ins for concrete types or other properties.
```rust
struct Point<T, U> {
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:
2017-03-03 14:50:30 +00:00
2018-12-07 14:56:43 +00:00
* **[in the current edition: Ch 10.00 — Generic Types, Traits, and Lifetimes][2]**
* <small>[In the first edition: Ch 3.18 — Generics][1]</small>
2018-12-07 14:56:43 +00:00
[1]: https://doc.rust-lang.org/1.30.0/book/first-edition/generics.html
[2]: ch10-00-generics.html
Fix links to second edition on redirect pages Search engines often show the redirect page for search terms like "rust topic" or "rust book topic". Currently the redirect targets all go to the index.html of the second edition of the book. This discourages users to use the second edition, because many will click on the direct link to the first edition out of laziness. In addition, as long as the pages of the second edition are not well linked, the old pages will probably stay at the top of the search results. To fix this, this commit changes the target links to go to the related content in the second edition, in the following way: Old content maps in different ways to new content: 1. 1:1 mapping content is comprehensively covered in a single location of the second edition 2. basic/advanced mapping content is comprehensively covered in two locations of the second edition; first location covers the basics, second location covers advanced topics 3. split mapping content is covered in muliple locations of the second edition 4. moved content has moved to another place 5. removed content doesn't exist in the second edition This commit handles these cases in the following way: 1. Mapping type 1: 1:1 mapping Change the link target from "second-edition/index.html" to the respective chapter, page or section of the second edition. Change the link text from "Index of the second edition..." to either of: - "Related chapter in the second edition" - "Related page in the second edition" - "Related section in the second edition" "Related" was chosen because content of two versions is at least related but not necessarily equivalent. Example: closures.md 2. Mapping type 2: basic/advanced mapping Change the link target from "second-edition/index.html" to the respective chapter, page or section of the second edition. Add a second link target for the advanced chapter, page or section. Change the link text like for type 1. Add the second link with the following text: "Related chapter in the second edition of The Rust Programming Language (covering more advanced topics)". Similar to the messages of type 2 there are variants with "page" and "section". Example: lifetimes.md 3. Mapping type 3: split mapping Change similar to changes for type 2. but add multiple links with text in parens describing relationship. 4. Mapping type 4: moved No changes. Example: compiler-plugins.md 5. Mapping type 5: removed No changes. See "Improvements" below. Example: attributes.md Improvements: This commit tries to introduce the target links with a minimum of changes. Copy was adapted only to the extent absolutely necessary. This leaves room for improvements: - Better deal with case 3. Describe mapping in copy not only link text. Actually refer to the links in the body copy. - Redirect pages of type 5 (content doesn't exist in second edition) should distinguish between "Content removed for good" and "Content not ready yet". For the latter category we could link to stub pages. All the new links were tested manually. The html was produced by a little script that invokes rustdoc, builds the book and copies everything into place. The script is not part of this commit. Here is a list with all mappings: associated-types.html -1-> ch19-03-advanced-traits.html#associated-types attributes.html -5-> index.html bibliography.html -5-> index.html borrow-and-asref.html -5-> index.html casting-between-types.html -5-> index.html choosing-your-guarantees.html ~1~> ch15-00-smart-pointers.html closures.html -1-> ch13-01-closures.html comments.html -1-> ch03-04-comments.html compiler-plugins.html -4-> ../unstable-book/language-features/plugin.html concurrency.html -1-> ch16-00-concurrency.html conditional-compilation.html -5-> index.html const-and-static.html ~1~> ch19-01-unsafe-rust.html#accessing-or-modifying-a-mutable-static-variable crates-and-modules.html -3-> Modules: ch07-00-modules.html Crates: ch14-00-more-about-cargo.html deref-coercions.html ~1~> ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods documentation.html ~1~> ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments drop.html -1-> ch15-03-drop.html effective-rust.html -5-> index.html enums.html -1-> ch06-01-defining-an-enum.html error-handling.html -1-> ch09-00-error-handling.html ffi.html -1-> ch19-01-unsafe-rust.html#calling-an-unsafe-function-or-method functions.html -1-> ch03-03-how-functions-work.html generics.html -1-> ch10-00-generics.html getting-started.html ~1~> ch01-00-introduction.html glossary.html -5-> index.html guessing-game.html -1-> ch02-00-guessing-game-tutorial.html if-let.html -1-> ch06-03-if-let.html if.html -1-> ch03-05-control-flow.html#if-expressions iterators.html -1-> ch13-02-iterators.html lifetimes.html -2-> ch10-03-lifetime-syntax.html ch19-02-advanced-lifetimes.html loops.html -1-> ch03-05-control-flow.html#repetition-with-loops macros.html -5-> index.html (appendix-05-macros.html is in TOC, but doesn't exist) match.html -2-> ch06-02-match.html -2-> ch18-00-patterns.html method-syntax.html -1-> ch05-03-method-syntax.html mutability.html -1-> ch03-01-variables-and-mutability.html operators-and-overloading.html -1-> ch19-03-advanced-traits.html#operator-overloading-and-default-type-parameters ownership.html -1-> ch04-00-understanding-ownership.html patterns.html -2-> ch06-02-match.html#patterns-that-bind-to-values ch18-03-pattern-syntax.html primitive-types.html ~1~> ch03-02-data-types.html procedural-macros.html -5-> index.html (appendix-05-macros.html is in TOC, but doesn't exist) raw-pointers.html ~1~> ch19-01-unsafe-rust.html#dereferencing-a-raw-pointer references-and-borrowing.html -1-> ch04-02-references-and-borrowing.html release-channels.html -5-> index.hmtl strings.html ~2~> ch04-03-slices.html#string-slices [Should be type 3 maybe with distinction &str and String] ~2~> ch08-02-strings.html structs.html -1-> ch05-00-structs.html syntax-and-semantics.html ~3~> ch03-00-common-programming-concepts.html appendix-01-keywords.html appendix-02-operators.html appendix-05-macros.html [WIP] syntax-index.html -5-> index.html testing.html -1-> ch11-00-testing.html the-stack-and-the-heap.html -5-> index.html trait-objects.html -1-> ch17-02-trait-objects.html traits.html -2-> ch10-02-traits.html ch19-03-advanced-traits.html type-aliases.html ~1~> ch19-04-advanced-types.html#type-aliases-create-type-synonyms ufcs.html -5-> index.html unsafe.html ~1~> ch19-01-unsafe-rust.html unsized-types.html ~1~> ch19-04-advanced-types.html#dynamically-sized-types--sized using-rust-without-the[..].html -5-> index.html variable-bindings.html -5-> index.html vectors.html -1-> ch08-01-vectors.html
2017-10-23 19:07:33 +00:00