- 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. The string type
- 6.5. Slices -- borrowing subranges
- 6.6. Lifetimes of references
- 6.7. Smart pointers
- 6.8. Unsafe Rust
- 6.9. Comparison with C
- 6.10. Summary
- 6.11. 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. Using Cargo
19. Collections and Container Types
20. Pattern Matching in Detail
21. Threads and Concurrency
22. Smart Pointers
23. Testing
24. Appendix
- 25. Private policy