pub struct ComponentInfo {
pub name: &'static str,
pub removable: bool,
pub register: fn(&mut World),
pub add: fn(&mut World, Entity),
pub remove: fn(&mut World, Entity),
pub has: fn(&World, Entity) -> bool,
pub to_json: fn(&World, Entity) -> Option<Value>,
pub from_json: fn(&mut World, Entity, Value) -> Result<(), String>,
pub validate: fn(&World, Entity) -> Result<(), String>,
pub edit: for<'a> fn(&'a mut World, Entity, &mut dyn FnMut(Vec<Field<'a>>)),
}Expand description
Type-erased editor/persistence operations for a registered component. Callback functions are host-owned; they must outlive every registry using them.
Fields§
§name: &'static strStable component name, matching the ECS storage name.
removable: boolWhether user-facing removal should be permitted.
register: fn(&mut World)Creates/checks the component storage in a fresh world using permanent host code.
add: fn(&mut World, Entity)Inserts a default value, replacing an existing one.
remove: fn(&mut World, Entity)Removes the component if present (does not enforce removable).
has: fn(&World, Entity) -> boolChecks presence on a living entity.
to_json: fn(&World, Entity) -> Option<Value>Serializes a present component; missing/unserializable values yield None.
from_json: fn(&mut World, Entity, Value) -> Result<(), String>Deserializes and inserts a component, reporting malformed values.
validate: fn(&World, Entity) -> Result<(), String>Checks that a present value can round-trip through its persisted serde representation. This rejects non-finite built-in floats that JSON would otherwise replace with null.
edit: for<'a> fn(&'a mut World, Entity, &mut dyn FnMut(Vec<Field<'a>>))Visits editable borrowed fields if the component exists.
Auto Trait Implementations§
impl Freeze for ComponentInfo
impl RefUnwindSafe for ComponentInfo
impl Send for ComponentInfo
impl Sync for ComponentInfo
impl Unpin for ComponentInfo
impl UnsafeUnpin for ComponentInfo
impl UnwindSafe for ComponentInfo
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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 moreimpl<T> MaybeSync for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.