
Ultimate Rust for Systems Programming
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Building Tomorrow's Systems Today the Rust Way
Book Description
This book is your guide to mastering Rust programming, equipping you with essential skills and insights for efficient system programming. It starts by introducing Rust's significance in the system programming domain and highlighting its advantages over traditional languages like C/C++. You'll then embark on a practical journey, setting up Rust on various platforms and configuring the development environment. From writing your first "Hello, World!" program to harness the power of Rust's package manager, Cargo, the book ensures a smooth initiation into the language.
Delving deeper, the book covers foundational concepts, including variables, data types, control flow, functions, closures, and crucial memory management aspects like ownership, borrowing, and lifetimes. Special attention is given to Rust's strict memory safety guarantees, guiding you in writing secure code with the assistance of the borrow checker.
The book extends its reach to Rust collections, error-handling techniques, and the complexities of concurrency management. From threads and synchronization primitives like Mutex and RwLock to asynchronous programming with async/await and the Tokio library, you'll gain a comprehensive understanding of Rust's capabilities. This book covers it all.
Table of Contents
1. Systems Programming with Rust
2. Basics of Rust
3. Traits and Generics
4. Rust Built-In Data Structures
5. Error Handling and Recovery
6. Memory Management and Pointers
7. Managing Concurrency
8. Command Line Programs
9. Working with Devices I/O in Rust
10. Iterators and Closures
11. Unit Testing in Rust
12. Network Programming
13. Unsafe Coding in Rust
14. Asynchronous Programming
15. Web Assembly with Rust
Index
More details
Content
- Cover Page
- Title Page
- Copyright Page
- Dedication Page
- About the Author
- About the Technical Reviewer
- Acknowledgements
- Preface
- Errata
- Table of Contents
- 1. Systems Programming with Rust
- Introduction
- Structure
- Safety and Performance
- Memory Protection
- Null Pointer Dereference
- Buffer Overflow
- Garbage Collector
- Multithreading and Parallelism
- Lifetimes
- Zero-Cost Abstractions
- Foreign Function Interface (FFI)
- Error Handling
- Controlled Unsafe Operations
- The Rust Toolbox
- Practical Applications
- Building a Future with Rust
- Supportive Community
- Exploring Beyond
- Notable Rust Projects
- Installing Rust
- Installing Rust on Windows
- Installing Rust on Linux
- Installing Rust on MacOS
- You're Ready to Rust!
- IDEs and Tools
- Choose Your IDE
- Visual Studio Code (VS Code)
- Essential Rust Tools
- The Package Manager
- The Linter
- Code Formatting
- Writing the first Rust program
- Getting Started
- Writing the Code
- Compiling and Running
- Cargo: Rust's package manager
- Getting to Know Cargo
- Creating a New Project
- Navigating the Project Structure
- Building and Running
- Managing Dependencies
- Testing and Documentation
- Exploring More Cargo Features
- Conclusion
- Additional Resources
- Multiple Choice Questions
- Answers
- Key Terms
- 2. Basics of Rust
- Introduction
- Structure
- Variables and Data Types
- Introduction to Variables
- Mutability
- Shadowing
- Constants
- Numeric Primitives
- Fixed-Width
- Integer Types
- Characters and Numeric Types
- Strings and Characters
- Character Iteration and String Operations
- Using Numeric Conversions
- Basic Mathematical Operations
- Addition
- Subtraction
- Multiplication
- Division
- Remainder
- Floating-Point Numbers
- f32 for Efficiency
- f64 for Precision
- Floating-Point Literals
- Mathematical Operations
- Navigating Complexities
- Approximate Equality
- Mastering Floating-Point Numbers
- Booleans for Logic
- Complex Data Types
- Strings
- Substrings
- Combining Strings
- Arrays
- Tuples
- Control Flow
- Conditional Statements
- While Loops
- For Loops
- Loop
- Match Expressions
- Functions
- Explicit Signatures
- Nested Functions for Modularity
- Closures
- Ownership, Borrowing, and Lifetimes
- Ownership
- Borrow Checker
- Enhancing Performance
- Conclusion
- Multiple Choice Questions
- Answers
- Key Terms
- 3. Traits and Generics
- Introduction
- Structure
- Traits
- Implementing Traits
- Default Trait Behavior
- Trait Bounds
- Expanding with Generics
- Generics
- Adaptive Structures
- Associated Functions
- Associated Types
- Trait Objects
- Real-World Applications
- Trait Bounds in the Standard Library
- Advanced Trait Patterns
- Associated Constants
- Operator Overloading
- Marker Traits
- Combining Traits
- Avoiding Trait Conflicts
- Blanket Implementations
- Supertraits
- Newtype Pattern
- Dynamically Sized Types (DSTs)
- Conditional Conformance
- Type-level Programming
- Performance Considerations
- Conclusion
- Multiple Choice Questions
- Answers
- 4. Rust Built-In Data Structures
- Introduction
- Structure
- Arrays in Rust
- Creating Arrays
- Accessing Array Elements
- Modifying Array Elements
- Iterating Through Arrays
- Slicing Arrays
- Multi-dimensional Arrays
- Working with Array Methods
- Array Initialization and Default Values
- Initializing with Default Values
- Generating Patterns with Iterators
- Initializing with Computed Values
- Array Length and Bounds Checking
- Obtaining the Length
- Bounds Checking
- Array Copy and Clone
- Copying Arrays
- Cloning Arrays
- Vectors
- Creating Vectors
- Accessing and Modifying Elements
- Modifying Vectors
- Adding Elements
- Updating Elements
- Removing Elements
- Iterating over Vectors
- Using a for Loop
- Using iter_mut for Mutable Iteration
- Using enumerate for Index and Value
- Tuples
- Creating and Initializing Tuples
- Accessing Tuple Elements
- Destructuring Tuples
- Tuple Patterns and Advanced Usage
- Real-World Use Cases
- Coordinating Coordinates
- Error Handling with Result Tuples
- Tuple Limitations
- Tuples in Pattern Matching
- Matching Tuples with Patterns
- Ignoring Tuple Elements
- Nested Tuples and Patterns
- Refutability of Tuple Patterns
- Tuple Ownership and Borrowing
- Tuple Ownership
- Borrowing Tuples
- Tuple Slicing and the Spread Operator
- Creating Tuple Slices
- Accessing Tuple Slices
- Tuple as Function Arguments and Return Values
- Using Tuples as Function Arguments
- Returning Tuples from Functions
- Tuple Variants in Enums
- Creating Enum Variants with Tuples
- Slices
- Understanding Slices
- Creating Slices
- Accessing Slice Elements
- Modifying Slice Elements
- Real-World Applications
- String Manipulation
- Data Processing
- Text Tokenization
- Binary Data Handling
- Memory Mapping
- Hash Sets in Rust
- Creating a Set
- Updating a Set
- Adding Elements
- Removing Elements
- Advanced Set Operations
- Symmetric Difference
- Subset and Superset Checking
- Real-World Applications
- Performance Considerations
- Concurrency Considerations
- Serialization and Deserialization
- Benchmarks and Optimization
- Hash Maps
- Creating a Hash Map
- Updating a Hash Map
- Adding Elements
- Removing Elements
- Updating an Element
- Accessing Values
- Iterating over Hash Maps
- Advanced Hash Map Operations
- Checking for Key Existence
- Entry API
- Clearing a Hash Map
- Hash Map Capacity
- Real-World Applications
- Counting Occurrences
- Memoization
- Caching
- Configuration Management
- Data Transformation
- Grouping Data
- Graph Algorithms
- Database Indexing
- Conclusion
- Additional Resources
- Multiple Choice Questions
- Answers
- 5. Error Handling and Recovery
- Introduction
- Structure
- Handling Errors using Result and Option
- Understanding Result and Option
- Handling Errors with Result
- Handling Errors with Option
- Error Propagation
- The ? Operator
- Handling Multiple Errors with Result
- Error Propagation with Result and Option
- Creating Custom Error Types
- Advanced Error Handling
- The anyhow Library
- Custom Error Types with thiserror
- Asynchronous Error Handling
- Async Functions and Results
- Custom Error Types for Async Code
- Handling Concurrency Errors
- Error Handling in Web Applications
- Putting it All Together
- File Parsing and Error Handling
- Error Handling in Command-Line Applications
- Using the clap Library
- Handling Signals and Interruptions
- Error Handling in File I/O
- Reading and Writing Files
- Working with Directories
- Error Handling in Network Programming
- Making HTTP Requests
- Building Network Services
- Error Handling in Multithreaded Code
- Cross-Thread Communication
- Testing and Error Handling
- Writing Error Tests
- Property-Based Testing
- Conclusion
- References and Further Reading
- Multiple-Choice Questions
- Answers
- 6. Memory Management and Pointers
- Introduction
- Structure
- The Role of Memory Management
- Challenges of Manual Memory Management
- Ownership and Borrowing
- Dangling References
- Unsafe Code
- Data Races
- Resource Management
- Stack versus Heap
- The Stack's Role in Rust
- The Heap's Role in Rust
- The Ownership Model
- Borrowing in Rust
- Lifetimes in Rust
- Pointers and Smart Pointers
- Box
- Rc
- Arc
- RefCell
- Mutex
- RwLock
- Atomic
- Unsafe Rust
- Unsafe Functions
- Unsafe Traits
- Custom Unsafe Abstractions
- Foreign Function Interface (FFI)
- Unsafe Code Guidelines
- Memory Management Best Practices
- Favor Stack Allocation
- Leverage References
- Use Smart Pointers Wisely
- Use Pattern Matching
- Lifetime Annotations
- Proper Resource Management
- Multithreading and Concurrency
- Unsafe Code with Caution
- Profiling and Optimization
- Advanced Memory Management
- Custom Memory Allocators
- Memory-Mapped Files
- Interoperability with Other Languages
- Memory Management Best Practices
- Conclusion
- 7. Managing Concurrency
- Introduction
- Structure
- Understanding Concurrent Programming
- Concurrency vs Parallelism
- Creating and Managing Threads
- Sharing Data Between Threads
- Concurrent Data Structures
- Basic Usage of Mutex
- Sharing Data Across Threads
- Avoiding Mutex Deadlocks
- Ownership of Mutex Guards
- Handling Poisoned Mutexes
- Advanced Usage of Mutex
- Conditional Locking
- Implementing a Mutex-Protected Queue
- Implementing a Mutex-Protected Priority Queue
- Handling Deadlocks with Mutex
- Mutex in Multi-Threaded Producer-Consumer Scenario
- Exploring RwLock
- Managing Shared Data with RwLock
- Advanced Usages of RwLock in Rust
- Dynamic Number of Readers
- Timed Locking
- Deadlock Avoidance
- Implementing Resource Pooling
- Thread Communication and Message Passing
- Using Channels for Communication
- Message Passing with Structs
- Atomic Operations
- Advanced Thread Communication
- Thread Coordination with Barriers
- Thread Local Storage
- Crossbeam Library
- Asynchronous Programming
- Concurrency Best Practices
- Conclusion
- Resources
- Multiple Choice Questions
- Answers
- Key Terms
- 8. Command Line Programs
- Introduction
- Structure
- Introduction to Argument Parsing
- Advantages of Choosing Clap
- Getting Started with clap
- Handling Multiple Arguments
- Handling Flag Arguments
- Advanced Argument Handling
- Implementing Text Search and Replace Logic
- Overview of Text Search and Replace
- Reading the Input File
- Find and Replace Logic
- Writing the Modified Content
- Case-Insensitive Search (Optional)
- Support for Multiple Input Files
- Conclusion
- Resources
- Multiple-Choice Questions
- Answers
- Key Terms
- 9. Working with Devices I/O in Rust
- Introduction
- Structure
- Reading from and Writing to Files
- Opening a File
- Reading from a File
- Writing to a File
- Closing a File
- Performing Common Filesystem Operations
- Creating Directories
- Renaming and Moving Files
- Checking File Metadata
- Deleting Files and Directories
- Traversing Directories
- Working with File Paths
- Reading and Writing Binary Data
- Error Handling and Result Types
- Working with Hardware Devices
- Advanced File Operations
- Symbolic Links and Hard Links
- Locking Files
- Memory-Mapped Files
- File I/O Best Practices
- Device Drivers and Kernel Modules
- Network Programming and Device I/O
- Sockets and Protocols
- Asynchronous Networking and Device I/O
- Networking Libraries and Device I/O
- Security Considerations
- Parallelism, Concurrency, and Device I/O
- Real-Time Systems and Device I/O
- Conclusion
- Resources
- Multiple Choice Questions
- Answers
- Key Terms
- 10. Iterators and Closures
- Introduction
- Structure
- Iterators
- Anatomy of an Iterator
- Key Traits: Iterator and IntoIterator
- Creating Iterators with from_fn and successors
- Drain Methods
- Other Iterator Sources
- Iterator Adapter Methods
- Building Custom Iterators
- Lazy Evaluation
- Advanced Techniques: flat_map, take, skip, and peekable
- flat_map
- take and skip
- peekable
- filter_map, fuse, and flatten
- filter_map
- fuse
- flatten
- The Magic of Closures
- Closure Syntax
- Variable Capture in Closures
- Borrowing Variables
- Moving Variables
- Closures and Fn, FnMut, FnOnce Traits
- Fn Closures
- FnMut Closures
- FnOnce Closures
- Iterators for Efficient Data Processing
- Accumulating Data with fold
- Chaining Iterators with chain
- Applying Iterators and Closures to Practical Examples
- Use Case 1: Text Analysis
- Use Case 2: Image Processing
- Use Case 3: Data Filtering and Transformation
- Use Case 4: Processing Sensor Data
- Use Case 5: Financial Calculations
- Use Case 6: Sorting
- Conclusion
- Resources
- Multiple Choice Questions
- Key Terms
- 11. Unit Testing in Rust
- Introduction
- Structure
- Unit Testing
- Writing Test Functions and Modules
- Writing a Basic Test Function
- Test Modules
- Tests and Test Results
- Running Tests
- Interpreting Test Results
- Assertions
- Custom Error Messages
- Running Tests with Options
- Fixtures and Setup Code
- Conditional Tests
- Asynchronous Testing
- Mocking Dependencies
- Testing Private Functions
- Benchmarking
- Code Coverage
- Continuous Integration
- Conclusion
- Resources
- Multiple Choice Questions
- Answers
- Key Terms
- 12. Network Programming
- Introduction
- Structure
- Network Programming
- Building Networked Applications
- Communication Protocols: TCP and UDP
- Transmission Control Protocol (TCP)
- User Datagram Protocol (UDP)
- Asynchronous Network Operations
- Asynchronous Programming
- Asynchronous TCP Server
- Real-World Use Cases: Handling HTTP Requests
- Networked Chat Application
- File Transfer Server
- Remote Command Execution Server
- Peer-to-Peer File Sharing
- Real-Time Collaborative Editing
- Conclusion
- Resources
- Multiple Choice Questions
- Answers
- Key Terms
- 13. Unsafe Coding in Rust
- Introduction
- Structure
- Unsafe Code
- Unsafe Blocks Scenarios
- Performance and Safety Considerations
- Real-World Examples
- Example 1: Database Interaction using FFI
- Example 2: Advanced Image Processing
- Example 3: Custom Memory Management
- Best Practices for using Unsafe Code
- Memory Safety Violations
- Case Studies
- Case Study 1: Heartbleed Vulnerability
- Case Study 2: Ariane 5 Flight 501 Failure
- Risks Associated with Unsafe Coding
- Risk 1: Null Pointer Dereferencing
- Risk 2: Buffer Overflows
- Risk 3: Use-After-Free Errors
- Conclusion
- Resources
- Multiple Choice Questions
- Answers
- Key Terms
- 14. Asynchronous Programming
- Introduction
- Structure
- Fundamentals of Rust's async/await Syntax
- Exploring the Dynamics of async/await
- Utilizing the tokio Library
- Using Async for Responsiveness
- Error Handling in Asynchronous Code
- Concurrent Task Lifetimes
- Advanced Patterns in Async Programming
- Asynchronous Streams
- Resource Management with Async Drop
- Fan-Out and Fan-In with Async Streams
- Cancelation and Timeout Handling
- Dynamic Task Management
- Integrating Async Code with Sync Code
- Conclusion
- Resources
- Multiple Choice Questions
- Answers
- Key Terms
- 15. Web Assembly with Rust
- Introduction
- Structure
- Advantages of WebAssembly
- WebAssembly Limitations
- Limited Browser Support
- Indirect DOM Manipulation
- Memory Management Challenges
- Rust for WebAssembly Development
- Installing Rust and WebAssembly Toolchain
- Setting Up a New Rust Wasm Project
- Building and Testing WebAssembly Modules
- Writing Wasm Rust Functions
- Testing the Web Assembly Module
- Real-world Applications of WebAssembly
- Use Case 1: Image Processing
- Use Case 2: Cryptographic Operations
- Use Case 3: Network Request Handling
- Conclusion
- Additional Resources
- Multiple Choice Questions
- Answers
- Index
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.