pub trait Index {
type Ref;
// Required method
fn get(&self, index: usize) -> Self::Ref;
// Provided methods
fn last(&self) -> Option<Self::Ref>
where Self: Len { ... }
fn iter(&self) -> IterOwn<&Self> ⓘ { ... }
fn into_iter(self) -> IterOwn<Self> ⓘ
where Self: Sized { ... }
}
Expand description
A type that can be accessed by usize
but without borrowing self
.
This can be useful for types which include their own lifetimes, and
which wish to express that their reference has the same lifetime.
In the GAT Index
, the Ref<'_>
lifetime would be tied to &self
.
This trait may be challenging to implement for owning containers,
for example Vec<_>
, which would need their Ref
type to depend
on the lifetime of the &self
borrow in the get()
function.
Required Associated Types§
Required Methods§
Provided Methods§
fn last(&self) -> Option<Self::Ref>where
Self: Len,
fn iter(&self) -> IterOwn<&Self> ⓘ
fn into_iter(self) -> IterOwn<Self> ⓘwhere
Self: Sized,
Object Safety§
This trait is not object safe.