pub struct Field<'a> {
pub name: &'static str,
pub value: FieldRef<'a>,
}Expand description
Named editable property shared by Inspector widgets and scene script properties.
use kvas_engine::reflect::Field;
let mut speed = 2.0;
{ let mut field = Field::f32("speed", &mut speed);
field.set_json(&serde_json::json!(3.0)); }
assert_eq!(speed, 3.0);Fields§
§name: &'static strStable property key used in scene JSON, undo and the Inspector.
value: FieldRef<'a>Borrowed value and editor presentation kind.
Implementations§
Source§impl<'a> Field<'a>
impl<'a> Field<'a>
Sourcepub fn f32(name: &'static str, v: &'a mut f32) -> Self
pub fn f32(name: &'static str, v: &'a mut f32) -> Self
Borrows a floating-point property under a stable field name.
Sourcepub fn u32(name: &'static str, value: &'a mut u32) -> Self
pub fn u32(name: &'static str, value: &'a mut u32) -> Self
Borrows an unsigned integer property without narrowing its range to i32.
Sourcepub fn vec3(name: &'static str, v: &'a mut Vec3) -> Self
pub fn vec3(name: &'static str, v: &'a mut Vec3) -> Self
Borrows a three-component vector property.
Sourcepub fn text(name: &'static str, v: &'a mut String) -> Self
pub fn text(name: &'static str, v: &'a mut String) -> Self
Borrows an editable string property.
Sourcepub fn asset(name: &'static str, v: &'a mut String, kind: AssetKind) -> Self
pub fn asset(name: &'static str, v: &'a mut String, kind: AssetKind) -> Self
Borrows an asset path with the specified picker category.
Sourcepub fn entity(name: &'static str, v: &'a mut String) -> Self
pub fn entity(name: &'static str, v: &'a mut String) -> Self
Borrows an entity-name reference; names are resolved by gameplay code.
Sourcepub fn choice<T: Choice + 'a>(name: &'static str, v: &'a mut T) -> Self
pub fn choice<T: Choice + 'a>(name: &'static str, v: &'a mut T) -> Self
Borrows an enum as a dropdown using its Choice implementation.
Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Copies the current reflected value into JSON. Non-finite numeric values serialize as null through serde_json.
Sourcepub fn set_json(&mut self, value: &Value)
pub fn set_json(&mut self, value: &Value)
Applies a JSON value; values of the wrong shape are ignored.
Sourcepub fn try_set_json(&mut self, value: &Value) -> bool
pub fn try_set_json(&mut self, value: &Value) -> bool
Applies a value only if its shape and numeric range match the field.
Returns false without mutation for invalid data, unknown choice labels,
integer overflow or non-finite float conversions.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Field<'a>
impl<'a> !Send for Field<'a>
impl<'a> !Sync for Field<'a>
impl<'a> !UnwindSafe for Field<'a>
impl<'a> Freeze for Field<'a>
impl<'a> Unpin for Field<'a>
impl<'a> UnsafeUnpin for Field<'a>
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.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§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.