Struct FieldRule

Source
pub struct FieldRule { /* private fields */ }
Expand description

A field’s registration rule and read-only introspection view.

Builders are checked by Schema::register. Rules obtained from a schema are already validated; inspection borrows the registered data without cloning.

use ferravex_play::authoring::{FieldRule, Schema, ValueKind};
let mut schema = Schema::new();
schema.register("body", &[
    FieldRule::required("mass", ValueKind::Number).range(0.0, 100.0),
    FieldRule::optional("count", ValueKind::Integer).integer_range(0, i64::MAX),
    FieldRule::optional("target", ValueKind::Reference).target("body"),
])?;
let mass = schema.field("body", "mass").unwrap();
assert_eq!(mass.name(), "mass");
assert_eq!(mass.kind(), ValueKind::Number);
assert!(mass.is_required());
assert_eq!(mass.number_bounds(), Some((0.0, 100.0)));
assert_eq!(mass.default_value(), None);
assert_eq!(schema.field("body", "count").unwrap().integer_bounds(), Some((0, i64::MAX)));
assert_eq!(schema.field("body", "target").unwrap().target_component(), Some("body"));

Implementations§

Source§

impl FieldRule

Source

pub fn required(name: &str, kind: ValueKind) -> FieldRule

Source

pub fn optional(name: &str, kind: ValueKind) -> FieldRule

Source

pub fn range(self, min: f64, max: f64) -> FieldRule

Source

pub fn integer_range(self, min: i64, max: i64) -> FieldRule

Source

pub fn target(self, component: &str) -> FieldRule

Source

pub fn name(&self) -> &str

The case-sensitive authored field name.

Source

pub fn kind(&self) -> ValueKind

The exact value type; integers and numbers are not interchangeable.

Source

pub fn is_required(&self) -> bool

Whether the field must exist on each concrete instance of its component. Prefab definitions may omit it until instance expansion supplies it.

Source

pub fn number_bounds(&self) -> Option<(f64, f64)>

Explicit inclusive bounds for a number or each vector/quaternion element. None adds no range restriction beyond the type’s built-in constraints.

Source

pub fn integer_bounds(&self) -> Option<(i64, i64)>

Explicit inclusive integer bounds, preserving all 64 bits of precision. None permits the entire i64 range.

Source

pub fn target_component(&self) -> Option<&str>

The component a referenced node must contain, if one was specified. References must still resolve when this returns None. A target’s component need not have been registered before this field’s component.

Source

pub fn default_value(&self) -> Option<&Value>

The schema-provided default, currently always None.

Schema rules do not supply values: omitted optional fields remain absent, and omitted required fields fail validation after prefab expansion. Prefab values and application fallbacks are outside the schema; this method does not guess a zero, identity or other type-based default.

Trait Implementations§

Source§

impl Clone for FieldRule

Source§

fn clone(&self) -> FieldRule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldRule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.