Skip to main content

AttachmentType

Struct AttachmentType 

pub struct AttachmentType<T>
where T: 'static,
{ pub namespace: &'static str, pub name: &'static str, pub default: fn() -> T, pub codec: Option<AttachmentCodec<T>>, pub copy_on_death: bool, pub sync: bool, }
Expand description

A mod-defined attachment key and its value’s behavior.

Fields§

§namespace: &'static str§name: &'static str§default: fn() -> T§codec: Option<AttachmentCodec<T>>§copy_on_death: bool§sync: bool

Send the value to the clients that see the holder; needs a codec.

Implementations§

§

impl<T> AttachmentType<T>
where T: Clone + Send + Sync + 'static,

pub fn get<S>( &self, store: &mut S, holder: Holder, ) -> Result<T, AttachmentError>
where S: AttachmentStore + ?Sized,

Read a value, inserting its default if absent; see get_existing.

pub fn has<S>( &self, store: &mut S, holder: Holder, ) -> Result<bool, AttachmentError>
where S: AttachmentStore + ?Sized,

Whether a holder carries a value, like NeoForge’s hasData; never inserts the default.

pub fn get_existing<S>( &self, store: &mut S, holder: Holder, ) -> Result<Option<T>, AttachmentError>
where S: AttachmentStore + ?Sized,

Read a value only if present, like getExistingData; a saved value decodes once.

pub fn set<S>( &self, store: &mut S, holder: Holder, value: T, ) -> Result<(), AttachmentError>
where S: AttachmentStore + ?Sized,

Replace a value on an existing holder. A key already decoded as a different type is rejected.

pub fn remove<S>( &self, store: &mut S, holder: Holder, ) -> Result<Option<T>, AttachmentError>
where S: AttachmentStore + ?Sized,

Remove a value from an existing holder. A saved value that does not decode is removed too, and its error returned.

pub fn sync_data<S>( &self, store: &mut S, holder: Holder, ) -> Result<(), AttachmentError>
where S: AttachmentStore + ?Sized,

Send the current value to the clients that see the holder.

Auto Trait Implementations§

§

impl<T> Freeze for AttachmentType<T>

§

impl<T> RefUnwindSafe for AttachmentType<T>

§

impl<T> Send for AttachmentType<T>

§

impl<T> Sync for AttachmentType<T>

§

impl<T> Unpin for AttachmentType<T>

§

impl<T> UnsafeUnpin for AttachmentType<T>

§

impl<T> UnwindSafe for AttachmentType<T>

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

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.