From b43b570d0084251047c501c70ffced0b3637c688 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 24 Feb 2017 22:52:33 -0500 Subject: [PATCH 1/3] re-work last few chapters Now that "Advanced type systems" is pretty much only two things, merging the lifetimes chapter, which is very short, into it makes a lot of sense. In addition, we kinda wanted to see if we could fit another project in here anyway, so let's do this and then it makes room! --- src/SUMMARY.md | 4 ++-- ...dvanced-types.md => ch19-00-advanced-features.md} | 12 ++++++++++++ src/ch19-00-more-lifetimes.md | 11 ----------- src/ch20-00-unnamed-project.md | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) rename src/{ch20-00-advanced-types.md => ch19-00-advanced-features.md} (87%) delete mode 100644 src/ch19-00-more-lifetimes.md create mode 100644 src/ch20-00-unnamed-project.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index ba2a8a24d..957ce4c39 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -88,9 +88,9 @@ - [Patterns](ch18-00-patterns.md) (perhaps an appendix?) -- [More Lifetimes](ch19-00-more-lifetimes.md) (perhaps merge this into advanced type system features?) +- [Advanced Features](ch19-00-advanced-features.md) -- [Advanced Type System Features](ch20-00-advanced-types.md) (perhaps called "Advanced Traits"?) +- [Un-named project](ch20-00-unnamed-project.md) - [Appendix](appendix-00.md) - [Keywords](appendix-01-keywords.md) diff --git a/src/ch20-00-advanced-types.md b/src/ch19-00-advanced-features.md similarity index 87% rename from src/ch20-00-advanced-types.md rename to src/ch19-00-advanced-features.md index 51f4899d4..9cea0d47b 100644 --- a/src/ch20-00-advanced-types.md +++ b/src/ch19-00-advanced-features.md @@ -33,6 +33,18 @@ You have to write unsafe code to FFI ### Unsafe Traits +## More Lifetimes + +### Lifetimes that depend on other lifetimes + +'a: 'b stuff: subtyping + +### Higher ranked trait bounds + +for<'a> + +Needed for closures + ## Associated Types More common than the other things, less common than the rest of the book diff --git a/src/ch19-00-more-lifetimes.md b/src/ch19-00-more-lifetimes.md deleted file mode 100644 index 535e16108..000000000 --- a/src/ch19-00-more-lifetimes.md +++ /dev/null @@ -1,11 +0,0 @@ -# More Lifetimes - -## Lifetimes that depend on other lifetimes - -'a: 'b stuff: subtyping - -## Higher ranked trait bounds - -for<'a> - -Needed for closures diff --git a/src/ch20-00-unnamed-project.md b/src/ch20-00-unnamed-project.md new file mode 100644 index 000000000..a2898c6b7 --- /dev/null +++ b/src/ch20-00-unnamed-project.md @@ -0,0 +1 @@ +# Un-named project From a40c79dca292ac19e1b9ff4e44e992cd1083db03 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 24 Feb 2017 23:05:39 -0500 Subject: [PATCH 2/3] write summary --- src/ch19-00-advanced-features.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ch19-00-advanced-features.md b/src/ch19-00-advanced-features.md index 9cea0d47b..4d2e275fb 100644 --- a/src/ch19-00-advanced-features.md +++ b/src/ch19-00-advanced-features.md @@ -1,4 +1,18 @@ -# Advanced Type System Features +# Advanced Features + +We've come a long way! By now, we've learned 99% of the things you'll need to +know when writing Rust. We'll wrap the book up by doing one more project, but +before we get to that, let's talk about a few things that you may run into that +last 1% of the time. Feel free to skip this chapter and come back to it once +you run into these things in the wild; the tools we'll learn to use here are +useful in very specific situations. We don't want to leave them out, but you +won't find yourself reaching for them often. + +Here's a quick summary: + +* Unsafe Rust: for when you need to tell Rust "just trust me, promise!" +* Advanced Lifetimes: Additional lifetime syntax for complex situations. +* Advanced Traits: Associated Types, coherence, and disambiguation. ## Unsafe Rust From d5a7a255f17ef94911905cf9b13ffc03697a49a9 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 24 Feb 2017 23:08:53 -0500 Subject: [PATCH 3/3] break into sections --- src/SUMMARY.md | 3 ++ src/ch19-00-advanced-features.md | 67 ------------------------------- src/ch19-01-unsafe-rust.md | 32 +++++++++++++++ src/ch19-02-advanced-lifetimes.md | 11 +++++ src/ch19-03-advanced-traits.md | 23 +++++++++++ 5 files changed, 69 insertions(+), 67 deletions(-) create mode 100644 src/ch19-01-unsafe-rust.md create mode 100644 src/ch19-02-advanced-lifetimes.md create mode 100644 src/ch19-03-advanced-traits.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 957ce4c39..b27866fb1 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -89,6 +89,9 @@ - [Patterns](ch18-00-patterns.md) (perhaps an appendix?) - [Advanced Features](ch19-00-advanced-features.md) + - [Unsafe Rust](ch19-01-unsafe-rust.md) + - [Advanced Lifetimes](ch19-02-advanced-lifetimes.md) + - [Advanced Traits](ch19-03-advanced-traits.md) - [Un-named project](ch20-00-unnamed-project.md) diff --git a/src/ch19-00-advanced-features.md b/src/ch19-00-advanced-features.md index 4d2e275fb..9e6aa1e28 100644 --- a/src/ch19-00-advanced-features.md +++ b/src/ch19-00-advanced-features.md @@ -13,70 +13,3 @@ Here's a quick summary: * Unsafe Rust: for when you need to tell Rust "just trust me, promise!" * Advanced Lifetimes: Additional lifetime syntax for complex situations. * Advanced Traits: Associated Types, coherence, and disambiguation. - -## Unsafe Rust - -Things you may do in an unsafe block that you may not in safe rust - -- deref a raw pointer -- call an unsafe fn -- access or modify a static variable -- impl an unsafe trait - -Go see other stuff - -Here's the syntax tho - -You know unsafe blocks are the cause of any crashes - -wrap all the unsafe, make it as small as possible, present a safe public API - -### Raw Pointers - -### Unsafe Functions - -#### `transmute` - -never ever. don't. stop. - -#### `extern fn` - -You have to write unsafe code to FFI - -### `static` - -### Unsafe Traits - -## More Lifetimes - -### Lifetimes that depend on other lifetimes - -'a: 'b stuff: subtyping - -### Higher ranked trait bounds - -for<'a> - -Needed for closures - -## Associated Types - -More common than the other things, less common than the rest of the book - -why this is a thing instead of a generic - -## The Thing Formerly Known as UFCS - -Only needed when implementing super generic code - -Lots of things are syntax sugar for this - -Two traits that impl the same method - how to disambiguate - -## Coherence - -Show examples of when you control traits and types or not - -Ex: Cannot impl Debug on someone else's type - -Solution: newtype diff --git a/src/ch19-01-unsafe-rust.md b/src/ch19-01-unsafe-rust.md new file mode 100644 index 000000000..6b4af7bf1 --- /dev/null +++ b/src/ch19-01-unsafe-rust.md @@ -0,0 +1,32 @@ +# Unsafe Rust + +Things you may do in an unsafe block that you may not in safe rust + +- deref a raw pointer +- call an unsafe fn +- access or modify a static variable +- impl an unsafe trait + +Go see other stuff + +Here's the syntax tho + +You know unsafe blocks are the cause of any crashes + +wrap all the unsafe, make it as small as possible, present a safe public API + +## Raw Pointers + +## Unsafe Functions + +### `transmute` + +never ever. don't. stop. + +### `extern fn` + +You have to write unsafe code to FFI + +## `static` + +## Unsafe Traits diff --git a/src/ch19-02-advanced-lifetimes.md b/src/ch19-02-advanced-lifetimes.md new file mode 100644 index 000000000..5e6f57c62 --- /dev/null +++ b/src/ch19-02-advanced-lifetimes.md @@ -0,0 +1,11 @@ +# Advanced Lifetimes + +### Lifetimes that depend on other lifetimes + +'a: 'b stuff: subtyping + +### Higher ranked trait bounds + +for<'a> + +Needed for closures diff --git a/src/ch19-03-advanced-traits.md b/src/ch19-03-advanced-traits.md new file mode 100644 index 000000000..3e8cfdcaa --- /dev/null +++ b/src/ch19-03-advanced-traits.md @@ -0,0 +1,23 @@ +# Advanced Traits + +## Associated Types + +More common than the other things, less common than the rest of the book + +why this is a thing instead of a generic + +## The Thing Formerly Known as UFCS + +Only needed when implementing super generic code + +Lots of things are syntax sugar for this + +Two traits that impl the same method - how to disambiguate + +## Coherence + +Show examples of when you control traits and types or not + +Ex: Cannot impl Debug on someone else's type + +Solution: newtype