pub struct Schema { /* private fields */ }Implementations§
Source§impl Schema
impl Schema
pub fn new() -> Schema
Sourcepub fn component_names(&self) -> impl ExactSizeIterator + DoubleEndedIterator
pub fn component_names(&self) -> impl ExactSizeIterator + DoubleEndedIterator
Registered component names in ascending, case-sensitive lexical order, independent of registration order. The iterator does not allocate.
use ferravex_play::authoring::Schema;
let mut schema = Schema::new();
schema.register("zebra", &[])?;
schema.register("actor", &[])?;
assert_eq!(schema.component_names().collect::<Vec<_>>(), ["actor", "zebra"]);Sourcepub fn fields(
&self,
component: &str,
) -> Option<impl ExactSizeIterator + DoubleEndedIterator>
pub fn fields( &self, component: &str, ) -> Option<impl ExactSizeIterator + DoubleEndedIterator>
Borrow a component’s rules in ascending field-name order without
allocation. None means an unknown component; an empty iterator means a
registered component with no fields. Inspection never mutates the rules.
use ferravex_play::authoring::{FieldRule, Schema, ValueKind};
let mut schema = Schema::new();
schema.register("body", &[
FieldRule::optional("size", ValueKind::Vec3),
FieldRule::required("mass", ValueKind::Number),
])?;
let names = schema.fields("body").unwrap().map(FieldRule::name).collect::<Vec<_>>();
assert_eq!(names, ["mass", "size"]);
assert!(schema.fields("unknown").is_none());
assert!(schema.field("body", "mass").unwrap().is_required());
assert!(schema.field("body", "missing").is_none());Sourcepub fn field(&self, component: &str, field: &str) -> Option<&FieldRule>
pub fn field(&self, component: &str, field: &str) -> Option<&FieldRule>
Borrow a validated rule, or return None for an unknown component/field.
See Self::fields for an inspection example.
Sourcepub fn write_json<W>(&self, writer: &mut W) -> Result<(), Error>
pub fn write_json<W>(&self, writer: &mut W) -> Result<(), Error>
Stream deterministic UTF-8 JSON describing registered component rules.
This is a separate introspection format, ferravex_scene_schema version
1, not a scene document, cooked data, or the JSON Schema standard. It
does not change either existing scene format. Components and fields are
arrays sorted by name; object keys have a fixed order. Empty components
are included, and unknown components/fields remain errors on load.
types describes built-in value constraints. Each field exports name,
type (its ValueKind::keyword), required, default, number_bounds,
integer_bounds, and target_component. Bounds are inclusive two-element
arrays, or null if no explicit bounds were registered. Number bounds
apply to each vector/quaternion element as well as scalar numbers.
Integer bounds are decimal strings, including the built-in i64
limits, so consumers do not round them through an IEEE-754 JSON number.
Every default is null: the schema never inserts a value. Prefab values
and application fallbacks cannot be inferred from component rules.
Output uses bounded schema storage directly, without an intermediate document or output buffer. Writer errors propagate immediately; on error the writer may contain a partial document, and the schema is unchanged. The caller controls flushing and any output-storage limit.
use ferravex_play::authoring::{FieldRule, Schema, ValueKind};
let mut schema = Schema::new();
schema.register("counter", &[
FieldRule::required("value", ValueKind::Integer).integer_range(0, i64::MAX),
])?;
let mut bytes = Vec::new();
schema.write_json(&mut bytes)?;
let json = String::from_utf8(bytes)?;
assert!(json.contains(r#""integer_bounds":["0","9223372036854775807"]"#));
assert!(json.contains(r#""default":null"#));