- 1. Rust for C programmers
- 1.1. Why Rust
- 1.2. What makes Rust special
- 1.3. About the book
1.4. About the authors
- 2. The basic tructure of a Rust program
- 2.1. The build system
- 2.2. The main function
- 2.3. Variables and mutability
- 2.4. Data types
- 2.5. Constants and statics
- 2.6. Functions and control flow
- 2.7. Modules and crates
- 2.8. Use statements and namespacing
- 2.9. Traits and implementations
- 2.10. Macros
- 2.11. Error handling
- 2.12. Memory safety and ownership
- 2.13. Expressions_and_Statements
- 2.14. Code conventions and style
- 2.15. Comments and documentation
- 2.16. Additional topics
- 2.17. Summary
- 2.18. Closing thoughts
- 3. Installing Rust
- 3.1. For Linux users
- 3.2. Experimenting in the playground
- 4. Rustc and Cargo
- 4.1. Compiling with Rustc
- 4.2. Introduction to Cargo
- 4.3. Further resources
- 5. Common_programming_concepts
- 5.1. Keywords
- 5.2. Expressions and statements
- 5.3. Data types
- 5.4. Variables and mutability
- 5.5. Operators
- 5.6. Numeric literals and their type
- 5.7. Overflow for arithmetic operations
- 5.8. Performance for numeric types
- 5.9. Comments in Rust
- 5.10. Summary
- 5.11. Closing thoughts
- 6. Ownership and memory management
- 6.1. Overview of ownership
- 6.2. Moves, cloning, and copying
- 6.3. Borrowing and references
- 6.4. Borrowing rules in detail
- 6.5. The string type
- 6.6. Slices -- borrowing subranges
- 6.7. Lifetimes of references
- 6.8. Smart pointers
- 6.9. Unsafe Rust
- 6.10. Comparison with C
- 6.11. Summary
- 6.12. Closing thoughts
- 7. Control flow
- 7.1. Conditional statements
- 7.2. Loops
- 7.3. Control flow in Rust and C
- 7.4. Summary
- 7.5. Closing_thoughts
- 8. Functions
- 8.1. Defining and calling functions
- 8.2. The main function
- 8.3. Parameters and return types
- 8.4. Default and named arguments
- 8.5. Slices as parameters
- 8.6. Tuples as parameters
- 8.7. Function pointers
- 8.8. Nested functions and scope
- 8.9. Generics in functions
- 8.10. Recursion
- 8.11. Inlining functions
- 8.12. Method call syntax
- 8.13. Function overloading
- 8.14. Type inference for return types
- 8.15. Variadic functions and macros
- 8.16. Summary
- 8.17. Exercises
- 8.18. Closing thoughts
- 9. Structs
- 9.1. Defining structs
- 9.2. Instantiating structs
- 9.3. Updating struct instances
- 9.4. Tuple structs
- 9.5. Unit like structs
- 9.6. Methods, associated functions
- 9.7. The self parameter
- 9.8. Getters and setters
- 9.9. Structs and ownership
- 9.10. References and lifetimes
- 9.11. Generic structs
- 9.12. Rust structs versus classes
- 9.13. Derived traits
- 9.14. Additional topics
- 9.15. Exercises
- 9.16. Summary
- 9.17. Closing thoughts
- 10. Enums and pattern matching
- 10.1. Understanding enums
- 10.2. Basic enums
- 10.3. Enums with data
- 10.4. Using enums in code
- 10.5. Memory layout of enums
- 10.6. Enums vs inheritance in OOP
- 10.7. Limitations of enums
- 10.8. Enums as function parameters
- 10.9. Option and Result types
- 10.10. Summary
- 10.11. Closing thoughts
- 11. Traits, generics, and lifetimes
- 11.1. Understanding traits
- 11.2. Generics in Rust
- 11.3. Lifetimes in Rust
- 11.4. Traits in depth
- 11.5. Advanced generics
- 11.6. Summary
- 11.7. Closing thoughts
- 12. Closures in Rust
- 12.1. Introduction to closures
- 12.2. Using closures
- 12.3. Closure traits
- 12.4. Working with closures
- 12.5. Closures and concurrency
- 12.6. Performance considerations
- 12.7. Additional topics
- 12.8. Summary
- 13. Mastering iterators
- 13.1. Introduction to iterators
- 13.2. Common iterator methods
- 13.3. Creating custom iterators
- 13.4. Advanced iterator concepts
- 13.5. Performance considerations
- 13.6. Practical examples
- 13.7. Additional topics
- 13.8. Iterators for complex structures
- 13.9. Summary
- 14. Option types
- 14.1. Introduction to option types
- 14.2. Using option types
- 14.3. Option types in other languages
- 14.4. Performance considerations
- 14.5. Benefits of using option types
- 14.6. Best practices
- 14.7. Practical examples
- 14.8. Summary
- 15. Error handling with Result
- 15.1. Introduction to error handling
- 15.2. Unrecoverable errors
- 15.3. The Result type
- 15.4. Error propagation with ?
- 15.5. Practical examples
- 15.6. Handling multiple error types
- 15.7. Best practices
- 15.8. Summary
- 16. Type conversions
- 16.1. Introduction to type conversions
- 16.2. Casting with as
- 16.3. Using the From and Into traits
- 16.4. Fallible conversions
- 16.5. Reinterpreting data types
- 16.6. String processing and parsing
- 16.7. Best practices
- 16.8. Summary
- 17. Crates, modules, and packages
- 17.1. Packages
- 17.2. Crates
- 17.3. Modules
- 17.4. The prelude
- 17.5. Best practices
- 17.6. Summary
- 18. Common collection types
- 18.1. Vectors
- 18.2. Strings
- 18.3. HashMaps
- 18.4. Other collection
- 18.5. Performance considerations
- 18.6. Selection guide
- 18.7. Summary
- 19. Smart pointers
- 19.1. The concept of smart pointers
- 19.2. Smart pointers vs. references
- 19.3. Comparing to C and C++
- 19.4. Box -- a simple smart pointer
- 19.5. Rc -- shared_ownership
- 19.6. Interior mutability
- 19.7. Shared ownership across threads
- 19.8. Weak -- non owning references
- 19.9. Summary
- 20. Object oriented programming
- 20.1. Definition of OOP
- 20.2. Problems and criticisms
- 20.3. OOP in Rust
- 20.4. Trait objects
- 20.5. Disadvantages of trait objects
- 20.6. Trait objects vs. enums
- 20.7. Modules and encapsulation
- 20.8. Generics instead of OOP
- 20.9. Serializing trait objects
- 20.10. Summary
- 21. Patterns and pattern matching
- 21.1. C's switch statement
- 21.2. Overview of patterns
- 21.3. Refutable vs irrefutable patterns
- 21.4. Variable assignment as a pattern
- 21.5. Match expressions
- 21.6. Matching enums
- 21.7. Matching literals and ranges
- 21.8. Underscores and the .. pattern
- 21.9. Variable bindings with @
- 21.10. Match guards
- 21.11. Or patterns and guards
- 21.12. Destructuring complex types
- 21.13. Matching boxed types
- 21.14. If let and while let
- 21.15. The let else construct
- 21.16. Patterns in for loops
- 21.17. Nested patterns
- 21.18. Performance considerations
- 21.19. Summary
- 22. Fearless concurrency
- 22.1. Concurrency, processes, threads
- 22.2. Concurrency vs true parallelism
- 22.3. Threads vs async
- 22.4. IO bound vs CPU bound tasks
- 22.5. Creating threads
- 22.6. Sharing data between threads
- 22.7. Channels for message passing
- 22.8. Rayon for data parallelism
- 22.9. SIMD
- 22.10. Comparison to C++
- 22.11. Send and sync traits
- 22.12. Summary
23. Useful traits
24. Using Cargo
25. Testing
26. Macros
27. Async
28. Unsafe Rust
29. Appendix
- 30. Private policy