pub struct Write<T: IsResource, G: Gen<T> = SomeDefault>(_, _);Expand description
A mutably 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 by 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. To make sure that your async functions don’t hold fetched
resources over await points, Facade uses visit which
fetches inside a syncronous closure.
Write has two type parameters:
T- The type of the resource.G- The method by which the resource can be generated if it doesn’t already exist. By default this isSomeDefault, which denotes creating the resource using its default implementation. 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 Write<T, G>
impl<'a, T: IsResource, G: Gen<T> + IsResource> CanFetch for Write<T, G>
sourceimpl<T: IsResource, G: Gen<T>> Deref for Write<T, G>
impl<T: IsResource, G: Gen<T>> Deref for Write<T, G>
sourceimpl<T: IsResource, G: Gen<T>> DerefMut for Write<T, G>
impl<T: IsResource, G: Gen<T>> DerefMut for Write<T, G>
sourceimpl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoIterator for &'a Write<T, G>where
&'a T: IntoIterator,
impl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoIterator for &'a Write<T, G>where
&'a T: IntoIterator,
sourceimpl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoIterator for &'a mut Write<T, G>where
&'a mut T: IntoIterator,
impl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoIterator for &'a mut Write<T, G>where
&'a mut T: IntoIterator,
type Item = <<&'a mut T as IntoIterator>::IntoIter as Iterator>::Item
type Item = <<&'a mut T as IntoIterator>::IntoIter as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = <&'a mut T as IntoIterator>::IntoIter
type IntoIter = <&'a mut T as IntoIterator>::IntoIter
Which kind of iterator are we turning this into?
sourceimpl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoParallelIterator for &'a Write<T, G>where
&'a T: IntoParallelIterator,
impl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoParallelIterator for &'a Write<T, G>where
&'a T: IntoParallelIterator,
type Item = <&'a T as IntoParallelIterator>::Item
type Item = <&'a T as IntoParallelIterator>::Item
The type of item that the parallel iterator will produce.
type Iter = <&'a T as IntoParallelIterator>::Iter
type Iter = <&'a T as IntoParallelIterator>::Iter
The parallel iterator type that will be created.
sourcefn into_par_iter(self) -> Self::Iter
fn into_par_iter(self) -> Self::Iter
Converts
self into a parallel iterator. Read moresourceimpl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoParallelIterator for &'a mut Write<T, G>where
&'a mut T: IntoParallelIterator,
impl<'a, T: Send + Sync + 'static, G: Gen<T>> IntoParallelIterator for &'a mut Write<T, G>where
&'a mut T: IntoParallelIterator,
type Item = <&'a mut T as IntoParallelIterator>::Item
type Item = <&'a mut T as IntoParallelIterator>::Item
The type of item that the parallel iterator will produce.
type Iter = <&'a mut T as IntoParallelIterator>::Iter
type Iter = <&'a mut T as IntoParallelIterator>::Iter
The parallel iterator type that will be created.
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> RefUnwindSafe for Write<T, G>where
G: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, G> Send for Write<T, G>where
G: Send,
impl<T, G> Sync for Write<T, G>where
G: Sync,
impl<T, G> Unpin for Write<T, G>where
G: Unpin,
impl<T, G> UnwindSafe for Write<T, G>where
G: UnwindSafe,
T: UnwindSafe,
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 moresourceimpl<'data, I> IntoParallelRefMutIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
impl<'data, I> IntoParallelRefMutIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
type Iter = <&'data mut I as IntoParallelIterator>::Iter
type Iter = <&'data mut I as IntoParallelIterator>::Iter
The type of iterator that will be created.
type Item = <&'data mut I as IntoParallelIterator>::Item
type Item = <&'data mut I as IntoParallelIterator>::Item
The type of item that will be produced; this is typically an
&'data mut T reference. Read moresourcefn par_iter_mut(
&'data mut self
) -> <I as IntoParallelRefMutIterator<'data>>::Iter
fn par_iter_mut(
&'data mut self
) -> <I as IntoParallelRefMutIterator<'data>>::Iter
Creates the parallel iterator from
self. Read more