diff --git a/src/SUMMARY.md b/src/SUMMARY.md index ba2a8a24d..b27866fb1 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -88,9 +88,12 @@ - [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) + - [Unsafe Rust](ch19-01-unsafe-rust.md) + - [Advanced Lifetimes](ch19-02-advanced-lifetimes.md) + - [Advanced Traits](ch19-03-advanced-traits.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/ch19-00-advanced-features.md b/src/ch19-00-advanced-features.md new file mode 100644 index 000000000..9e6aa1e28 --- /dev/null +++ b/src/ch19-00-advanced-features.md @@ -0,0 +1,15 @@ +# 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. 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/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 diff --git a/src/ch20-00-advanced-types.md b/src/ch20-00-advanced-types.md deleted file mode 100644 index 51f4899d4..000000000 --- a/src/ch20-00-advanced-types.md +++ /dev/null @@ -1,56 +0,0 @@ -# Advanced Type System Features - -## 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 - -## 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/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