pub struct EntityJsonParser<'e, 's, S = NoEntitiesSchema> { /* private fields */ }Expand description
Struct used to parse entities from JSON.
Implementations§
Source§impl<'e, 's, S> EntityJsonParser<'e, 's, S>
impl<'e, 's, S> EntityJsonParser<'e, 's, S>
Sourcepub fn new(
schema: Option<&'s S>,
extensions: &'e Extensions<'e>,
tc_computation: TCComputation,
) -> Self
pub fn new( schema: Option<&'s S>, extensions: &'e Extensions<'e>, tc_computation: TCComputation, ) -> Self
Create a new EntityJsonParser.
schema represents a source of Action entities, which will be added
to the entities parsed from JSON.
(If any Action entities are present in the JSON, and a schema is
also provided, each Action entity in the JSON must exactly match its
definition in the schema or an error is returned.)
If a schema is present, this will also inform the parsing: for
instance, it will allow __entity and __extn escapes to be implicit.
Finally, if a schema is present, the EntityJsonParser will ensure
that the produced entities fully conform to the schema – for
instance, it will error if attributes have the wrong types (e.g., string
instead of integer), or if required attributes are missing or
superfluous attributes are provided.
If you pass TCComputation::AssumeAlreadyComputed, then the caller is
responsible for ensuring that TC holds before calling this method.
Source§impl<S: Schema> EntityJsonParser<'_, '_, S>
impl<S: Schema> EntityJsonParser<'_, '_, S>
Sourcepub fn from_json_str(&self, json: &str) -> Result<Entities, EntitiesError>
pub fn from_json_str(&self, json: &str) -> Result<Entities, EntitiesError>
Sourcepub fn from_json_value(&self, json: Value) -> Result<Entities, EntitiesError>
pub fn from_json_value(&self, json: Value) -> Result<Entities, EntitiesError>
Parse an entities JSON file (in serde_json::Value form) into an Entities object.
If the EntityJsonParser has a schema, this also adds Action
entities declared in the schema.
Sourcepub fn from_json_file(&self, json: impl Read) -> Result<Entities, EntitiesError>
pub fn from_json_file(&self, json: impl Read) -> Result<Entities, EntitiesError>
Parse an entities JSON file (in std::io::Read form) into an Entities object.
If the EntityJsonParser has a schema, this also adds Action
entities declared in the schema.
Sourcepub fn iter_from_json_str(
&self,
json: &str,
) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
pub fn iter_from_json_str( &self, json: &str, ) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
Sourcepub fn iter_from_json_value(
&self,
json: Value,
) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
pub fn iter_from_json_value( &self, json: Value, ) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
Parse an entities JSON file (in serde_json::Value form) into an iterator over Entitys.
If the EntityJsonParser has a schema, this also adds Action
entities declared in the schema.
Sourcepub fn iter_from_json_file(
&self,
json: impl Read,
) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
pub fn iter_from_json_file( &self, json: impl Read, ) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
Parse an entities JSON file (in std::io::Read form) into an iterator over Entitys.
If the EntityJsonParser has a schema, this also adds Action
entities declared in the schema.
Sourcepub fn single_from_json_value(
&self,
value: Value,
) -> Result<Entity, EntitiesError>
pub fn single_from_json_value( &self, value: Value, ) -> Result<Entity, EntitiesError>
Parse a single entity from an in-memory JSON value
Sourcepub fn single_from_json_str(
&self,
src: impl AsRef<str>,
) -> Result<Entity, EntitiesError>
pub fn single_from_json_str( &self, src: impl AsRef<str>, ) -> Result<Entity, EntitiesError>
Parse a single entity from a JSON string
Sourcepub fn single_from_json_file(
&self,
r: impl Read,
) -> Result<Entity, EntitiesError>
pub fn single_from_json_file( &self, r: impl Read, ) -> Result<Entity, EntitiesError>
Parse a single entity from a JSON reader
Trait Implementations§
Source§impl<'e, 's, S: Clone> Clone for EntityJsonParser<'e, 's, S>
impl<'e, 's, S: Clone> Clone for EntityJsonParser<'e, 's, S>
Source§fn clone(&self) -> EntityJsonParser<'e, 's, S>
fn clone(&self) -> EntityJsonParser<'e, 's, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<'e, 's, S> Freeze for EntityJsonParser<'e, 's, S>
impl<'e, 's, S = NoEntitiesSchema> !RefUnwindSafe for EntityJsonParser<'e, 's, S>
impl<'e, 's, S> Send for EntityJsonParser<'e, 's, S>where
S: Sync,
impl<'e, 's, S> Sync for EntityJsonParser<'e, 's, S>where
S: Sync,
impl<'e, 's, S> Unpin for EntityJsonParser<'e, 's, S>
impl<'e, 's, S = NoEntitiesSchema> !UnwindSafe for EntityJsonParser<'e, 's, S>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more