pub struct Read<T: IsResource, G: Gen<T> = SomeDefault> { /* private fields */ }Expand description
Immutably borrowed resource that may be created by default.
Read and Write are the main way systems interact with resources.
When fetched The wrapped type T will
automatically be created b default. If fetched as Write<T, NoDefault> the
fetch will err if the resource doesn’t already exist.
After a successful fetch, the resource will be automatically sent back to the world on drop.
Read has two type parameters:
T- The type of the resource.G- The method by which the resource can be generated if it doesn’t exist. By default this isSomeDefault, which denotes creating the resource using its default instance. Another option isNoDefaultwhich fails to generate the resource.
use apecs::*;
let mut world = World::default();
{
let default_number = world.fetch::<Read<u32>>();
assert_eq!(Some(0), default_number.map(|n| *n).ok());
}
{
let no_number = world.fetch::<Read<f32, NoDefault>>();
assert!(no_number.is_err());
}Implementations
Trait Implementations
sourceimpl<'a, T: IsResource, G: Gen<T> + IsResource> CanFetch for Read<T, G>
impl<'a, T: IsResource, G: Gen<T> + IsResource> CanFetch for Read<T, G>
sourceimpl<'a, T: IsResource, G: Gen<T>> Deref for Read<T, G>
impl<'a, T: IsResource, G: Gen<T>> Deref for Read<T, G>
sourceimpl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoIterator for &'a Read<T, G>where
&'a T: IntoIterator,
impl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoIterator for &'a Read<T, G>where
&'a T: IntoIterator,
sourceimpl<'a, S: Send + Sync + 'static, G: Gen<S>> IntoParallelIterator for &'a Read<S, G>where
&'a S: IntoParallelIterator,
impl<'a, S: Send + Sync + 'static, G: Gen<S>> IntoParallelIterator for &'a Read<S, G>where
&'a S: IntoParallelIterator,
type Iter = <&'a S as IntoParallelIterator>::Iter
type Iter = <&'a S as IntoParallelIterator>::Iter
The parallel iterator type that will be created.
type Item = <&'a S as IntoParallelIterator>::Item
type Item = <&'a S as IntoParallelIterator>::Item
The type of item that the parallel iterator will produce.
sourcefn into_par_iter(self) -> Self::Iter
fn into_par_iter(self) -> Self::Iter
Converts
self into a parallel iterator. Read moreAuto Trait Implementations
impl<T, G = SomeDefault> !RefUnwindSafe for Read<T, G>
impl<T, G> Send for Read<T, G>where
G: Send,
impl<T, G> Sync for Read<T, G>where
G: Sync,
impl<T, G> Unpin for Read<T, G>where
G: Unpin,
T: Unpin,
impl<T, G = SomeDefault> !UnwindSafe for Read<T, G>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<'data, I> IntoParallelRefIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
impl<'data, I> IntoParallelRefIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
type Iter = <&'data I as IntoParallelIterator>::Iter
type Iter = <&'data I as IntoParallelIterator>::Iter
The type of the parallel iterator that will be returned.
type Item = <&'data I as IntoParallelIterator>::Item
type Item = <&'data I as IntoParallelIterator>::Item
The type of item that the parallel iterator will produce.
This will typically be an
&'data T reference type. Read moresourcefn par_iter(&'data self) -> <I as IntoParallelRefIterator<'data>>::Iter
fn par_iter(&'data self) -> <I as IntoParallelRefIterator<'data>>::Iter
Converts
self into a parallel iterator. Read more