Traits: A Deep dive
Traits과 관련하여 유명한 Nell님의 톡 및 Rust 관련 주제 공식 문서들. 일단 Rust Book을 이해하는 것이 가장 우선됨.
특히, 19장 Advanced Traits은 읽어야함. 관련 기법을 사용한 코드 때문에 이해하는데 어려움이 있었음.
Traits and You: A Deep Dive — Nell Shamrell-Harrington
- Rust Book
doc.rust-lang.org/book/ch10-02-traits.html
Traits: Defining Shared Behavior - The Rust Programming Language
A trait tells the Rust compiler about functionality a particular type has and can share with other types. We can use traits to define shared behavior in an abstract way. We can use trait bounds to specify that a generic can be any type that has certain beh
doc.rust-lang.org
doc.rust-lang.org/book/ch19-03-advanced-traits.html
Advanced Traits - The Rust Programming Language
We first covered traits in the “Traits: Defining Shared Behavior” section of Chapter 10, but as with lifetimes, we didn’t discuss the more advanced details. Now that you know more about Rust, we can get into the nitty-gritty. Associated types connect
doc.rust-lang.org
doc.rust-lang.org/book/ch17-02-trait-objects.html
Using Trait Objects That Allow for Values of Different Types - The Rust Programming Language
In Chapter 8, we mentioned that one limitation of vectors is that they can store elements of only one type. We created a workaround in Listing 8-10 where we defined a SpreadsheetCell enum that had variants to hold integers, floats, and text. This meant we
doc.rust-lang.org
- Rust By Example
doc.rust-lang.org/rust-by-example/trait.html
Traits - Rust By Example
A trait is a collection of methods defined for an unknown type: Self. They can access other methods declared in the same trait. Traits can be implemented for any data type. In the example below, we define Animal, a group of methods. The Animal trait is the
doc.rust-lang.org
- Rust Reference
doc.rust-lang.org/reference/items/traits.html
Traits - The Rust Reference
Syntax Trait : unsafe? trait IDENTIFIER GenericParams? ( : TypeParamBounds? )? WhereClause? { InnerAttribute* AssociatedItem* } A trait describes an abstract interface that types can implement. This interface consists of assoc
doc.rust-lang.org
doc.rust-lang.org/reference/types/trait-object.html
Trait object types - The Rust Reference
Syntax TraitObjectType : dyn? TypeParamBounds TraitObjectTypeOneBound : dyn? TraitBound A trait object is an opaque value of another type that implements a set of traits. The set of traits is made up of an object safe base trait plus any number o
doc.rust-lang.org
- Rustonomicon
doc.rust-lang.org/nomicon/hrtb.html
Higher-Rank Trait Bounds - The Rustonomicon
Rust's Fn traits are a little bit magic. For instance, we can write the following code: struct Closure { data: (u8, u16), func: F, } impl Closure where F: Fn(&(u8, u16)) -> &u8, { fn call(&self) -> &u8 { (self.func)(&self.data) } } fn do_it(data: &(u8, u16
doc.rust-lang.org