Provider

Struct Provider 

Source
pub struct Provider<E, V> { /* private fields */ }
Expand description

Key-value container of a V value for every possible E.

Implementations§

Source§

impl<E, V> Provider<E, V>
where E: BlockModule,

Source

pub async fn new<F>( progress: YieldProgress, definer: F, ) -> Result<Self, GenError>
where F: FnMut(E) -> Result<V, InGenError>,

Constructs a Provider with values computed by the given function.

This is an async function for the sake of cancellation and optional cooperative multitasking. It may be blocked on from a synchronous context (but if that is the only use, consider calling Provider::new_sync() instead).

Source§

impl<E: BlockModule> Provider<E, Block>

Source

pub async fn new_installed_cyclic<F>( progress: YieldProgress, txn: &mut UniverseTransaction, definer: F, ) -> Result<Self, GenError>

Constructs a BlockProvider with BlockDefs whose block values are computed by the given function.

The module itself is passed to definer, which may be used to create relationships among the blocks (e.g. one having the behavior of turning into another). Attempting to read those handles will necessarily fail.

Source

pub fn install( &self, read_ticket: ReadTicket<'_>, txn: &mut UniverseTransaction, ) -> Result<Self, InsertError>

Add the block definitions stored in this BlockProvider into universe as BlockDefs, returning a new BlockProvider whose blocks refer to those definitions (via Primitive::Indirect).

The given read_ticket should be sufficient for evaluating the blocks in self.

Source

pub fn using(universe: &Universe) -> Result<Self, ProviderError>
where E: Eq + Hash + Display,

Obtain the definitions of E’s blocks from universe, returning a new BlockProvider whose blocks refer to those definitions (via Primitive::Indirect).

Returns an error if any of the blocks are not defined in that universe.

Source§

impl<E: Exhaust + Debug + Clone + Eq + Hash, V> Provider<E, V>

These methods do not require E to be a BlockModule.

Source

pub fn new_sync<F>(definer: F) -> Self
where F: FnMut(E) -> V,

Alternative to Self::new() which is neither async nor fallible.

Source

pub fn subset<K>(&self, function: impl Fn(K) -> E) -> Provider<K, V>
where K: Exhaust + Debug + Clone + Eq + Hash, V: Clone,

Create another Provider with different keys that map into a subset of this provider’s keys.

TODO: add a test

Source

pub fn map<V2>(&self, function: impl FnMut(&E, &V) -> V2) -> Provider<E, V2>

Create another Provider with a modification to each value.

Source

pub fn iter(&self) -> ModuleIter<'_, E, V>

Iterate over the entire contents of this.

Trait Implementations§

Source§

impl<E: Clone, V: Clone> Clone for Provider<E, V>

Source§

fn clone(&self) -> Provider<E, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Debug, V: Debug> Debug for Provider<E, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E, V> Default for Provider<E, V>
where E: DefaultProvision<V> + Exhaust + Eq + Hash + Clone,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<E: Eq + Hash, V> Index<&E> for Provider<E, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: &E) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<E: Eq + Hash, V> Index<E> for Provider<E, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: E) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'provider, E: Exhaust + Debug + Clone + Eq + Hash, V> IntoIterator for &'provider Provider<E, V>

Source§

type Item = (E, &'provider V)

The type of the elements being iterated over.
Source§

type IntoIter = ModuleIter<'provider, E, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E: Eq + Hash, V: PartialEq> PartialEq for Provider<E, V>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<E: Eq + Hash + VisitHandles, V: VisitHandles> VisitHandles for Provider<E, V>

Source§

fn visit_handles(&self, visitor: &mut dyn HandleVisitor)

For each Handle contained within self that is reachable without traversing another Handle, call visitor with a reference to it.
Source§

impl<E: Eq + Hash, V: PartialEq> Eq for Provider<E, V>

Auto Trait Implementations§

§

impl<E, V> Freeze for Provider<E, V>

§

impl<E, V> RefUnwindSafe for Provider<E, V>

§

impl<E, V> Send for Provider<E, V>
where E: Send, V: Send,

§

impl<E, V> Sync for Provider<E, V>
where E: Sync, V: Sync,

§

impl<E, V> Unpin for Provider<E, V>
where E: Unpin, V: Unpin,

§

impl<E, V> UnwindSafe for Provider<E, V>
where E: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,