pub trait Fields<K, V> {
type Key<'k>
where Self: 'k;
type Val<'v>
where Self: 'v;
// Required method
fn fields<'s>(&'s self) -> impl IteratorTrait;
}
Expand description
A trait for iterating over fields convertible to a specified type within an entity.
This trait provides a mechanism for accessing fields in collections or entities, converting them into a desired type for iteration.
§Type Parameters
K
: The key type, typically representing the index or identifier of each field.V
: The value type that fields are converted into during iteration.
§Associated Types
Val<'v>
: The type of value yielded by the iterator, parameterized by a lifetime'v
. This ensures the values’ lifetimes are tied to the entity being iterated over.
§Example
use reflect_tools::{ Fields, IteratorTrait };
struct MyCollection< V >
{
data : Vec< V >,
}
impl< V > Fields< usize, &V > for MyCollection< V >
{
type Key< 'k > = usize where V : 'k;
type Val< 'v > = & 'v V where Self : 'v;
fn fields( & self ) -> impl IteratorTrait< Item = ( usize, Self::Val< '_ > ) >
{
self.data.iter().enumerate()
}
}
This example shows MyCollection
implementing Fields
, allowing iteration over its elements
with both index and value.
Required Associated Types§
Required Methods§
Sourcefn fields<'s>(&'s self) -> impl IteratorTrait
fn fields<'s>(&'s self) -> impl IteratorTrait
Returns an iterator over fields of the specified type within the entity.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.