Struct Schema

Source
pub struct Schema { /* private fields */ }

Implementations§

Source§

impl Schema

Source

pub fn new() -> Schema

Source

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"]);
Source

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());
Source

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.

Source

pub fn write_json<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + ?Sized,

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"#));
Source

pub fn register( &mut self, name: &str, fields: &[FieldRule], ) -> Result<(), ContentError>

Registration is transactional; unknown components/properties are errors on load. Integer bounds stay i64, without a lossy floating-point comparison.

Trait Implementations§

Source§

impl Default for Schema

Source§

fn default() -> Schema

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Schema

§

impl RefUnwindSafe for Schema

§

impl Send for Schema

§

impl Sync for Schema

§

impl Unpin for Schema

§

impl UnwindSafe for Schema

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> 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, 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.