Trait |
Description |
Copy |
Copy is a marker trait, so it has no methods for application code to call.
It's used by compiler to decide how to handle bindings and assignments.
If the data is Copy its value is copied from source to destination.
|
Clone |
Clone creates a new instance of the cloner type and copies into it the cloner's resources.
This is an expensive operation so Rust makes that explicit with the fn clone(&self) -> Self method.
|
Debug |
Debug enables functions and structs to use the Debug format specifier "{:?}".
That formats output in a relatively simple fashion, intended for debugging code, but useful elsewhere
as well. The Rust primitives and most of the Rust library types implement this Trait.
|
Display
|
Display provides custom formatting for user-defined functions and structs with the
"{}" format placeholder. Some of the Rust types, like Strings,
implement Display.
|
Default
|
Default requires implementors to supply the associated function fn default() -> Self.
This is intended to allow users of the implementing type to set a default value for an
instance of the type at construction.
|
ToString
|
ToString requires the method: fn to_string(&self) -> String.
This trait is automatically implemented for types that implement Display trait. The
Rust docs say "ToString shouldn't be implemented directly: Display should
be implemented instead, ..."
|
From and
Into
|
From requires the method: fn from(T) -> Self. That produces a value
conversion that consumes the original value. Into requires: fn into(self) -> T
with the same result. Implementing From automatically implements Into, but the reverse
is not true, so you should favor implementing From.
|
FromStr
|
FromStr requires the function fn from_str(s: &str) -> Result<Self, Self::Err>
This function is usually used implicitly through str's parse method.
|
AsRef
|
AsRef requires the function: fn as_ref(&self) -> &T and the Trait ?Sized.
The type of String.as_ref() is &String. AsRef allows a function accepting an &str to
accept any type that implements AsRef<String>.
|
Deref
|
Deref specifies the function: fn deref(&self) -> &Serlf::Target and requires
the associated type: type Target: ?Sized;. It is used to silently convert
a reference, r, into its referend, as if you invoked *r.
|
Sized and
?Sized
|
Sized is a marker trait for types with constant size known at compile time. The ?Sized
trait means that the type size is not known at compile time, e.g., a heap-based array.
|
Read
|
Read specifies function:
fn read(&mut self, buf: &mut [u8]) -> Result<usize>. The std::io::Read
provides many additional useful functions.
|
Write
|
Write specifies the function:
fn write(&mut self, buf: &[u8]) -> Result<usize>. std::io::Write
also specifies many additional useful functions.
|
Iterator
|
Iterator specifies the function: fn next(&mut self) -> Option<Self::Item>
where item is an associated type: type Item;. Iterator has many additional
methods that make it useful for operating on collections.
|
IntoIterator
|
IntoIterator specifies the function: fn into_iter(self) -> Self::IntoIter
where Item is an associated type: type Item; and IntoIter is also an associated
type: type IntoIter: Iterator;. IntoIterator defines how a collection type
converts to an Iterator.
|