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 is SomeDefault, which denotes creating the resource using its default implementation. Another option is NoDefault which 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

An explicit method of getting a reference to the inner type without Deref.

An explicit method of getting a mutable reference to the inner type without DerefMut.

Trait Implementations

Attempt to construct Self with the given LoanManager.
Return a plugin containing the systems and sub-resources required to create and use the type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of item that the parallel iterator will produce.
The parallel iterator type that will be created.
Converts self into a parallel iterator. Read more
The type of item that the parallel iterator will produce.
The parallel iterator type that will be created.
Converts self into a parallel iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type of the parallel iterator that will be returned.
The type of item that the parallel iterator will produce. This will typically be an &'data T reference type. Read more
Converts self into a parallel iterator. Read more
The type of iterator that will be created.
The type of item that will be produced; this is typically an &'data mut T reference. Read more
Creates the parallel iterator from self. Read more
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.