Enum all_is_cubes::inv::Tool

source ·
#[non_exhaustive]
pub enum Tool { Activate, RemoveBlock { keep: bool, }, Block(Block), InfiniteBlocks(Block), CopyFromSpace, EditBlock, PushPull, Jetpack { active: bool, }, Custom { op: Operation, icon: Block, }, ExternalAction { function: EphemeralOpaque<dyn Fn(&ToolInput) + Send + Sync>, icon: Block, }, }
Expand description

A Tool is an object which a character can use to have some effect in the game, such as placing or removing a block. In particular, a tool use usually corresponds to a click.

Currently, Tools also play the role of “inventory items”. This may change in the future.

§Serialization stability warning

This type implements serde::Serialize and serde::Deserialize, but serialization support is still experimental (as is the game data model in general). We do not guarantee that future versions of all-is-cubes will be able to deserialize data which is serialized by this version.

Additionally, the serialization schema is designed with serde_json in mind. It is not guaranteed that using a different data format crate, which may use a different subset of the information exposed via serde::Serialize, will produce stable results.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Activate

“Click”, or “push button”, or generally “activate the function of this” as opposed to editing it.

This can activate an ActivatableRegion. It may have more functions in the future.

§

RemoveBlock

Fields

§keep: bool

If true, move it to inventory. If false, discard it entirely.

Delete any targeted block from the space.

§

Block(Block)

Move the given block out of inventory (consuming this tool) into the targeted empty space.

§

InfiniteBlocks(Block)

Places copies of the given block in targeted empty space. Infinite uses.

§

CopyFromSpace

Copy block from space to inventory.

§

EditBlock

Teleport into a block’s space for editing.

TODO: This is not yet actually implemented.

§

PushPull

Push targeted block into adjacent cube.

§

Jetpack

Fields

§active: bool

Actually currently flying?

Allows flight.

TODO: This should probably be a feature a tool can have rather than a single-purpose item, but we don’t yet have a plan for programmable items.

§

Custom

Fields

§op: Operation

Operation to perform when the tool is used.

§icon: Block

Icon for the tool.

A tool which performs an arbitrary Operation.

§

ExternalAction

Fields

§function: EphemeralOpaque<dyn Fn(&ToolInput) + Send + Sync>

Function that will be called when the tool is activated.

§icon: Block

Icon for the tool.

A tool which calls an arbitrary function. TODO: This is not used and should perhaps be folded into Custom

Implementations§

source§

impl Tool

source

pub fn use_tool( self, input: &ToolInput ) -> Result<(Option<Self>, UniverseTransaction), ToolError>

Computes the effect of using the tool.

The effect consists of both mutations to self and a UniverseTransaction. If the result is None then the tool is deleted. If the transaction does not succeed, the original Tool value should be kept.

TODO: Return type is inelegant

source

pub fn use_immutable_tool( &self, input: &ToolInput ) -> Result<UniverseTransaction, ToolError>

As Self::use_tool, except that it does not allow the tool to modify itself.

This operation is used for special cases where an action is expressed by a tool but the tool is not a “game item”.

source

pub fn icon<'a>( &'a self, predefined: &'a BlockProvider<Icons> ) -> Cow<'a, Block>

Return a block to use as an icon for this tool. For tools that place blocks, has the same appearance as the block to be placed. The display name of the block should be the display name of the tool.

TODO (API instability): Eventually we will probably want additional decorations that probably should not need to be painted into the block itself.

Trait Implementations§

source§

impl Clone for Tool

source§

fn clone(&self) -> Tool

Returns a copy 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 Debug for Tool

source§

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

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

impl<'de> Deserialize<'de> for Tool

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Tool> for Slot

source§

fn from(tool: Tool) -> Self

Converts to this type from the input type.
source§

impl Hash for Tool

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Tool

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Tool

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl VisitRefs for Tool

source§

fn visit_refs(&self, visitor: &mut dyn RefVisitor)

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

impl Eq for Tool

source§

impl StructuralEq for Tool

source§

impl StructuralPartialEq for Tool

Auto Trait Implementations§

§

impl !RefUnwindSafe for Tool

§

impl Send for Tool

§

impl Sync for Tool

§

impl Unpin for Tool

§

impl !UnwindSafe for Tool

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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, 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.

§

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

§

type EqTo = T

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,

§

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>,

§

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>,

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,