Struct all_is_cubes::block::BlockDef
source · pub struct BlockDef { /* private fields */ }Expand description
Contains a Block and can be stored in a Universe.
Together with Primitive::Indirect, this allows mutation of a block definition such
that all its existing usages follow.
To perform such a mutation, use BlockDefTransaction.
Additionally, it caches the results of block evaluation to improve performance.
Note that this cache only updates when the owning Universe is being stepped, or when
a direct mutation to this BlockDef is performed, not when the contained Block
sends a change notification.
Implementations§
source§impl BlockDef
impl BlockDef
sourcepub fn new(block: Block) -> Self
pub fn new(block: Block) -> Self
Constructs a new BlockDef that stores the given block (which may be replaced
in the future).
sourcepub fn block(&self) -> &Block
pub fn block(&self) -> &Block
Returns the current block value.
Note that if you wish to get the EvaluatedBlock result, you should obtain the cached
value by calling BlockDef.evaluate(), or by using a Primitive::Indirect,
not by calling .block().evaluate(), which is not cached.
sourcepub fn evaluate(&self) -> Result<EvaluatedBlock, EvalBlockError>
pub fn evaluate(&self) -> Result<EvaluatedBlock, EvalBlockError>
Returns the current cached evaluation of the current block value.
This returns the same success or error as Block::from(handle_to_self).evaluate() would,
not the same as .block().evaluate() would.
Trait Implementations§
source§impl<'a> Arbitrary<'a> for BlockDef
impl<'a> Arbitrary<'a> for BlockDef
source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moresource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moresource§impl Listen for BlockDef
impl Listen for BlockDef
source§fn listen<L: Listener<BlockChange> + 'static>(&self, listener: L)
fn listen<L: Listener<BlockChange> + 'static>(&self, listener: L)
Registers a listener for whenever the result of evaluation of this block definition changes.
Note that this only occurs when the owning Universe is being stepped.
§type Msg = BlockChange
type Msg = BlockChange
source§impl Transactional for BlockDef
impl Transactional for BlockDef
§type Transaction = BlockDefTransaction
type Transaction = BlockDefTransaction
Self.source§fn transact<F, O>(&mut self, f: F) -> Result<O, ExecuteError<Self::Transaction>>where
F: FnOnce(&mut Self::Transaction, &Self) -> Result<O, <Self::Transaction as Merge>::Conflict>,
Self::Transaction: Transaction<Target = Self, Output = NoOutput> + Default,
fn transact<F, O>(&mut self, f: F) -> Result<O, ExecuteError<Self::Transaction>>where
F: FnOnce(&mut Self::Transaction, &Self) -> Result<O, <Self::Transaction as Merge>::Conflict>,
Self::Transaction: Transaction<Target = Self, Output = NoOutput> + Default,
self,
equivalent to the following steps: Read moresource§impl UTransactional for BlockDef
impl UTransactional for BlockDef
source§fn bind(
target: Handle<Self>,
transaction: Self::Transaction,
) -> UniverseTransaction
fn bind( target: Handle<Self>, transaction: Self::Transaction, ) -> UniverseTransaction
source§impl VisitHandles for BlockDef
impl VisitHandles for BlockDef
source§fn visit_handles(&self, visitor: &mut dyn HandleVisitor)
fn visit_handles(&self, visitor: &mut dyn HandleVisitor)
Auto Trait Implementations§
impl Freeze for BlockDef
impl RefUnwindSafe for BlockDef
impl Send for BlockDef
impl Sync for BlockDef
impl Unpin for BlockDef
impl UnwindSafe for BlockDef
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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