- Hands-On Data Structures and Algorithms with Rust
- Claus Matzinger
- 217字
- 2021-07-02 14:11:50
Summary
Moving one level above the details of code, this chapter discusses considerations when designing and using types. Rust's differentiation between stack- and heap-allocated variables in code provides a level of control that should be used to improve performance and API flexibility. Sized, a marker trait for mostly stack-allocated values, is the default for generic type parameters and can be relaxed by applying the ?Sized constraint instead.
When working with more object-oriented architectures, trait objects become a way to "work with interfaces" instead of specific implementations. However, they come at a performance cost, that is, dynamic dispatch, another trade-off between maintainability and performance.
Other than moving, Rust can copy or clone variables when necessary. Copy performs a deep copy in the case of sized values; unsized values require a reference that has to be cloned instead. Using these operations is often encountered when working with immutable data types in a principle called copy-on-write. Choosing whether we are able to reason about the object's state at any given time and avoiding data race conditions, but having to create a copy for each change, is another important trade-off when designing data structures.
This trade-off will become apparent in the next chapter, where we will start working with lists, such as the singly-linked list, doubly-linked list, and the dynamic array.
- LibGDX Game Development Essentials
- Java Data Science Cookbook
- Spark大數據分析實戰
- 云計算服務保障體系
- 大數據時代下的智能轉型進程精選(套裝共10冊)
- Remote Usability Testing
- 數字媒體交互設計(初級):Web產品交互設計方法與案例
- AI時代的數據價值創造:從數據底座到大模型應用落地
- PostgreSQL指南:內幕探索
- 數據挖掘競賽實戰:方法與案例
- 企業級大數據項目實戰:用戶搜索行為分析系統從0到1
- 數據中臺實戰:手把手教你搭建數據中臺
- 標簽類目體系:面向業務的數據資產設計方法論
- 成功之路:ORACLE 11g學習筆記
- 反饋:化解不確定性的數字認知論