Skip to main content

Component

Trait Component 

pub trait Component {
    type Value;

    // Required methods
    fn id(&self) -> &str;
    fn decode(&self, value: &Tag) -> Option<Self::Value>;
    fn encode(&self, value: Self::Value) -> Tag;
}
Expand description

A typed descriptor for one component in an item’s component patch. Implementations own the conversion between their value and Minecraft NBT.

Required Associated Types§

type Value

The value returned by this descriptor.

Required Methods§

fn id(&self) -> &str

Canonical component name, including its namespace.

fn decode(&self, value: &Tag) -> Option<Self::Value>

Decode a component value, refusing an incompatible NBT representation.

fn encode(&self, value: Self::Value) -> Tag

Encode a component value.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§