Comprehensive Rust 🦀 (202302)
首页 白天 夜间 BookChat 小程序 小程序 下载 阅读记录
  • 书签 我的书签
  • 添加书签 添加书签 移除书签 移除书签

23.3. Important Traits

来源 Google 浏览 1 扫码 打印 2026-10-24 14:21:24
  • Important Traits

Important Traits

We will now look at some of the most common traits of the Rust standard library:

  • Iterator and IntoIterator used in for loops,
  • From and Into used to convert values,
  • Read and Write used for IO,
  • Add, Mul, … used for operator overloading, and
  • Drop used for defining destructors.
  • Default used to construct a default instance of a type.
上一篇:
下一篇:
  • 书签
  • 添加书签 移除书签
  • 0. Welcome to Comprehensive Rust 🦀
  • 1. Running the Course
    • 1.1. Course Structure
    • 1.2. Keyboard Shortcuts
    • 1.3. Translations
  • 2. Using Cargo
    • 2.1. Rust Ecosystem
    • 2.2. Code Samples
    • 2.3. Running Cargo Locally
  • Day 1: Morning
    • 3. Welcome
      • 3.1. What is Rust?
    • 4. Hello World!
      • 4.1. Small Example
    • 5. Why Rust?
      • 5.1. Compile Time Guarantees
      • 5.2. Runtime Guarantees
      • 5.3. Modern Features
    • 6. Basic Syntax
      • 6.1. Scalar Types
      • 6.2. Compound Types
      • 6.3. References
        • 6.3.1. Dangling References
      • 6.4. Slices
        • 6.4.1. String vs str
      • 6.5. Functions
        • 6.5.1. Methods
        • 6.5.2. Overloading
    • 7. Exercises
      • 7.1. Implicit Conversions
      • 7.2. Arrays and for Loops
  • Day 1: Afternoon
    • 8. Variables
      • 8.1. Type Inference
      • 8.2. static & const
      • 8.3. Scopes and Shadowing
    • 9. Memory Management
      • 9.1. Stack vs Heap
      • 9.2. Stack Memory
      • 9.3. Manual Memory Management
      • 9.4. Scope-Based Memory Management
      • 9.5. Garbage Collection
      • 9.6. Rust Memory Management
      • 9.7. Comparison
    • 10. Ownership
      • 10.1. Move Semantics
      • 10.2. Moved Strings in Rust
        • 10.2.1. Double Frees in Modern C++
      • 10.3. Moves in Function Calls
      • 10.4. Copying and Cloning
      • 10.5. Borrowing
        • 10.5.1. Shared and Unique Borrows
      • 10.6. Lifetimes
      • 10.7. Lifetimes in Function Calls
      • 10.8. Lifetimes in Data Structures
    • 11. Exercises
      • 11.1. Designing a Library
      • 11.2. Iterators and Ownership
  • Day 2: Morning
    • 12. Welcome
    • 13. Structs
      • 13.1. Tuple Structs
      • 13.2. Field Shorthand Syntax
    • 14. Enums
      • 14.1. Variant Payloads
      • 14.2. Enum Sizes
    • 15. Methods
      • 15.1. Method Receiver
      • 15.2. Example
    • 16. Pattern Matching
      • 16.1. Destructuring Enums
      • 16.2. Destructuring Structs
      • 16.3. Destructuring Arrays
      • 16.4. Match Guards
    • 17. Exercises
      • 17.1. Health Statistics
      • 17.2. Points and Polygons
  • Day 2: Afternoon
    • 18. Control Flow
      • 18.1. Blocks
      • 18.2. if expressions
      • 18.3. if let expressions
      • 18.4. while expressions
      • 18.5. while let expressions
      • 18.6. for expressions
      • 18.7. loop expressions
      • 18.8. match expressions
      • 18.9. break & continue
    • 19. Standard Library
      • 19.1. Option and Result
      • 19.2. String
      • 19.3. Vec
      • 19.4. HashMap
      • 19.5. Box
        • 19.5.1. Recursive Data Types
        • 19.5.2. Niche Optimization
      • 19.6. Rc
    • 20. Modules
      • 20.1. Visibility
      • 20.2. Paths
      • 20.3. Filesystem Hierarchy
    • 21. Exercises
      • 21.1. Luhn Algorithm
      • 21.2. Strings and Iterators
  • Day 3: Morning
    • 22. Welcome
    • 23. Traits
      • 23.1. Deriving Traits
      • 23.2. Default Methods
      • 23.3. Important Traits
        • 23.3.1. Iterator
        • 23.3.2. FromIterator
        • 23.3.3. From and Into
        • 23.3.4. Read and Write
        • 23.3.5. Add, Mul, …
        • 23.3.6. Drop
        • 23.3.7. Default
    • 24. Generics
      • 24.1. Generic Data Types
      • 24.2. Generic Methods
      • 24.3. Trait Bounds
      • 24.4. impl Trait
      • 24.5. Closures
      • 24.6. Monomorphization
      • 24.7. Trait Objects
    • 25. Exercises
      • 25.1. A Simple GUI Library
  • Day 3: Afternoon
    • 26. Error Handling
      • 26.1. Panics
        • 26.1.1. Catching Stack Unwinding
      • 26.2. Structured Error Handling
      • 26.3. Propagating Errors with ?
        • 26.3.1. Converting Error Types
          • 26.3.1.1. Example
        • 26.3.2. Deriving Error Enums
        • 26.3.3. Dynamic Error Types
        • 26.3.4. Adding Context to Errors
    • 27. Testing
      • 27.1. Unit Tests
      • 27.2. Test Modules
      • 27.3. Documentation Tests
      • 27.4. Integration Tests
    • 28. Unsafe Rust
      • 28.1. Dereferencing Raw Pointers
      • 28.2. Mutable Static Variables
      • 28.3. Unions
      • 28.4. Calling Unsafe Functions
        • 28.4.1. Writing Unsafe Functions
        • 28.4.2. Extern Functions
      • 28.5. Implementing Unsafe Traits
    • 29. Exercises
      • 29.1. Safe FFI Wrapper
  • Day 4: Morning
    • 30. Welcome
    • 31. Concurrency
      • 31.1. Threads
      • 31.2. Scoped Threads
      • 31.3. Channels
        • 31.3.1. Unbounded Channels
        • 31.3.2. Bounded Channels
      • 31.4. Shared State
        • 31.4.1. Arc
        • 31.4.2. Mutex
        • 31.4.3. Example
      • 31.5. Send and Sync
        • 31.5.1. Send
        • 31.5.2. Sync
        • 31.5.3. Examples
    • 32. Exercises
      • 32.1. Dining Philosophers
      • 32.2. Multi-threaded Link Checker
  • Day 4: Afternoon
    • 33. Android
      • 33.1. Setup
      • 33.2. Build Rules
        • 33.2.1. Binary
        • 33.2.2. Library
      • 33.3. AIDL
        • 33.3.1. Interface
        • 33.3.2. Implementation
        • 33.3.3. Server
        • 33.3.4. Deploy
        • 33.3.5. Client
        • 33.3.6. Changing API
      • 33.4. Logging
      • 33.5. Interoperability
        • 33.5.1. With C
          • 33.5.1.1. Calling C with Bindgen
          • 33.5.1.2. Calling Rust from C
        • 33.5.2. With C++
        • 33.5.3. With Java
    • 34. Exercises
  • Final Words
    • 35. Thanks!
    • 36. Other Resources
    • 37. Credits
  • Solutions
    • 38. Solutions
      • 38.1. Day 1 Morning
      • 38.2. Day 1 Afternoon
      • 38.3. Day 2 Morning
      • 38.4. Day 2 Afternoon
      • 38.5. Day 3 Morning
      • 38.6. Day 3 Afternoon
      • 38.7. Day 4 Morning
暂无相关搜索结果!

    本文档使用 WanXiangYunDang 构建

    展开/收起文章目录

    思维导图备注

    文章二维码

    手机扫一扫,轻松掌上读

    文档下载

    请下载您需要的格式的文档,随时随地,享受汲取知识的乐趣!
    PDF文档 EPUB文档 MOBI文档

    微信小程序阅读

    BookChat 微信小程序阅读
    微信扫一扫,知识掌上学

    书签列表

      阅读记录

      阅读进度: 0.00% ( 0/0 ) 重置阅读进度