pub struct Document { /* private fields */ }Implementations§
Source§impl Document
impl Document
pub fn parse(source: &str) -> Result<Document, ContentError>
Sourcepub fn parse_with_diagnostics(source: &str) -> Result<Document, SceneDiagnostic>
pub fn parse_with_diagnostics(source: &str) -> Result<Document, SceneDiagnostic>
Parse with an offending token, source excerpt and repair guidance.
Reports the same first error as Self::parse; schema validation requires
Self::load_with_diagnostics. No source is retained on success.
use ferravex_play::authoring::{Document, ErrorKind};
let source = "ferravex_scene 1;\nnode x { component body { mass number NaN; } }";
let error = Document::parse_with_diagnostics(source).unwrap_err();
assert_eq!(error.error.kind, ErrorKind::Range);
assert_eq!(error.error.span.line, 2);
assert_eq!(error.token.as_deref(), Some("NaN"));pub fn compile(&self, schema: &Schema) -> Result<SceneData, ContentError>
pub fn load(source: &str, schema: &Schema) -> Result<SceneData, ContentError>
Sourcepub fn load_with_diagnostics(
source: &str,
schema: &Schema,
) -> Result<SceneData, SceneDiagnostic>
pub fn load_with_diagnostics( source: &str, schema: &Schema, ) -> Result<SceneData, SceneDiagnostic>
Parse, expand and validate with source-aware diagnostics. In addition to
syntax hints, schema errors list allowed fields/components, required value
types and inclusive bounds. Reports the same first error as Self::load
and produces identical scene/cooked data on success.
use ferravex_play::authoring::{Document, FieldRule, Schema, ValueKind};
let mut schema = Schema::new();
schema.register("body", &[FieldRule::optional("mass", ValueKind::Number)])?;
let source = "ferravex_scene 1; node x { component body { mas number 1; } }";
let error = Document::load_with_diagnostics(source, &schema).err().unwrap();
assert_eq!(error.token.as_deref(), Some("mas"));
assert!(error.help.as_deref().unwrap().contains("mass"));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
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
Mutably borrows from an owned value. Read more