Translations
&T
Immutable reference to a value of type
T
.
&[T]
Reference to a slice containing data of type
T
.
impl<T> Queue<T>
For any type
T
, here are some methods available onQueue
.
fn say_hello(out: &mut Write)
This function's parameter is a mutable reference to any value that implements the
Write
trait
fn min<T: Ord>(value1: T, value2: T)
This function can be used with arguments of any type T that implements the
Ord
trait
fn top_ten<T: Debug + Hash + Eq>(values: &Vec<T>)
This function can be used with an argument that is a vector reference of any type
T
, as long asT
implements theDebug
,Hash
, andEq
traits
impl<W: Write> WriteHtml for W
Here's an implementation of the
WriteHtml
trait for any typeW
that implementsWrite
trait Creature: Visible {
Every type that implements
Creature
must also implement theVisible
trait.Creature
is a subtrait of (extends)Visible
.
trait Iterator { type Item;
Item
is an associated type of theIterator
trait. Any type that implementsIterator
must specify theItem
type.
impl Iterator for Args { type Item = String;
The implementation of
Iterator
forArgs
has an associated Item type ofString
.
fn dump<I>(iter: I) where I: Iterator<Item=String>
The type parameter
I
must be an iterator overString
values
trait Mul<RHS=Self> {
The type parameter
RHS
of this trait defaults toSelf
.
#![allow(unused)] fn main() { pub trait Rng { fn next_u32(&mut self) -> u32; } pub trait Rand: Sized { fn rand<R: Rng>(rng: &mut R) -> Self; } }
The
Rand
trait uses theRng
trait as a bound.Rand
andRng
are buddy traits.
impl<T> Add for Complex<T> where T: Add<Output=T>
Overloads the
+
operator for values ofComplex<T>
types, whereT
must already implement theAdd
(+
operator) trait.
trait PartialEq<Rhs: ?Sized = Self>
This is a trait signature whose
Rhs
type parameter does not have to be a sized type. That means this trait could be implemented for types like&str
or&[T]
. We'd say thatRhs
is questionably sized.
#![allow(unused)] fn main() { impl<T, E, C> FromIterator<Result<T, E>> for Result<C, E> where C: FromIterator<T> { ... } }
If you can collect items of type
T
into a collection of typeC
(whereC
implements theFromIterator<T>
trait), then you can collect items of typeResult<T, E>
into a single result of typeResult<C, E>
.