pub struct FieldStorage<T>where
T: Clone,{
pub inner: FieldStorageInner<T>,
}Expand description
Generic storage for PyBevy field types (non-Copy types like TextureAtlas)
Supports two modes:
Owned: Python-created value, stored in BoxBorrowed: Reference to field in a component (e.g., sprite.texture_atlas)
§Type Parameters
T: The field type (does not need to implementCopy)
§Safety
Borrowed variant contains a raw pointer to value data in a component.
The ValidityFlagWithMode ensures this pointer is only dereferenced during
system execution when the pointer is guaranteed to be valid.
Fields§
§inner: FieldStorageInner<T>Implementations§
Source§impl<T> FieldStorage<T>where
T: Clone,
impl<T> FieldStorage<T>where
T: Clone,
Sourcepub fn owned(value: T) -> FieldStorage<T>
pub fn owned(value: T) -> FieldStorage<T>
Create owned field storage with validity tracking
Sourcepub fn as_ref(&self) -> Result<&T, StorageError>
pub fn as_ref(&self) -> Result<&T, StorageError>
Get immutable reference to the value, checking validity
Sourcepub fn as_mut(&mut self) -> Result<&mut T, StorageError>
pub fn as_mut(&mut self) -> Result<&mut T, StorageError>
Get mutable reference to the value, checking validity and write permission
Sourcepub fn get(&self) -> Result<T, StorageError>
pub fn get(&self) -> Result<T, StorageError>
Get the current value (returns a clone)
Sourcepub fn borrow_field<F, S>(
&self,
field_accessor: impl Fn(&T) -> &F,
) -> Result<S, StorageError>where
F: Clone,
S: BorrowableStorage<F>,
pub fn borrow_field<F, S>(
&self,
field_accessor: impl Fn(&T) -> &F,
) -> Result<S, StorageError>where
F: Clone,
S: BorrowableStorage<F>,
Borrow a field from the stored value
Returns a borrowed reference to a nested field that can be mutated and have changes persist back to the original storage.
§Example
Prefer using borrow_field_as for simpler syntax:
#[getter]
pub fn physical_position(&self) -> PyResult<PyUVec2> {
self.storage.borrow_field_as(|v| &v.physical_position)
}Or use borrow_field directly when more control is needed:
let storage = self.storage.borrow_field(|v| &v.physical_position)?;
Ok(PyUVec2::from_borrowed(storage))Sourcepub fn borrow_field_as<F, S, W>(
&self,
field_accessor: impl Fn(&T) -> &F,
) -> Result<W, StorageError>
pub fn borrow_field_as<F, S, W>( &self, field_accessor: impl Fn(&T) -> &F, ) -> Result<W, StorageError>
Trait Implementations§
Source§impl<T> BorrowableStorage<T> for FieldStorage<T>where
T: Clone,
impl<T> BorrowableStorage<T> for FieldStorage<T>where
T: Clone,
Source§unsafe fn borrowed(
ptr: *mut T,
validity: ValidityFlagWithMode,
) -> FieldStorage<T>
unsafe fn borrowed( ptr: *mut T, validity: ValidityFlagWithMode, ) -> FieldStorage<T>
Source§impl<T> Clone for FieldStorage<T>where
T: Clone,
impl<T> Clone for FieldStorage<T>where
T: Clone,
Source§fn clone(&self) -> FieldStorage<T>
fn clone(&self) -> FieldStorage<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for FieldStorage<T>
impl<T> Debug for FieldStorage<T>
Source§impl<T> Drop for FieldStorage<T>where
T: Clone,
impl<T> Drop for FieldStorage<T>where
T: Clone,
Source§impl<T> PartialEq for FieldStorage<T>
impl<T> PartialEq for FieldStorage<T>
impl<T> Send for FieldStorage<T>
impl<T> Sync for FieldStorage<T>
Auto Trait Implementations§
impl<T> Freeze for FieldStorage<T>
impl<T> RefUnwindSafe for FieldStorage<T>where
T: RefUnwindSafe,
impl<T> Unpin for FieldStorage<T>
impl<T> UnsafeUnpin for FieldStorage<T>
impl<T> UnwindSafe for FieldStorage<T>where
T: RefUnwindSafe + UnwindSafe,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>, which can then be
downcast into Box<dyn 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>, which 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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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