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: boolSend the value to the clients that see the holder; needs a codec.
Implementations§
§impl<T> AttachmentType<T>
impl<T> AttachmentType<T>
pub fn get<S>(
&self,
store: &mut S,
holder: Holder,
) -> Result<T, AttachmentError>where
S: AttachmentStore + ?Sized,
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,
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,
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,
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,
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,
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> 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
Mutably borrows from an owned value. Read more