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
impl FieldRule
pub fn required(name: &str, kind: ValueKind) -> FieldRule
pub fn optional(name: &str, kind: ValueKind) -> FieldRule
pub fn range(self, min: f64, max: f64) -> FieldRule
pub fn integer_range(self, min: i64, max: i64) -> FieldRule
pub fn target(self, component: &str) -> FieldRule
Sourcepub fn kind(&self) -> ValueKind
pub fn kind(&self) -> ValueKind
The exact value type; integers and numbers are not interchangeable.
Sourcepub fn is_required(&self) -> bool
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.
Sourcepub fn number_bounds(&self) -> Option<(f64, f64)>
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.
Sourcepub fn integer_bounds(&self) -> Option<(i64, i64)>
pub fn integer_bounds(&self) -> Option<(i64, i64)>
Explicit inclusive integer bounds, preserving all 64 bits of precision.
None permits the entire i64 range.
Sourcepub fn target_component(&self) -> Option<&str>
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.
Sourcepub fn default_value(&self) -> Option<&Value>
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.