cedar_policy_core::entities::json

Struct EntityJsonParser

Source
pub struct EntityJsonParser<'e, 's, S: Schema = NoEntitiesSchema> { /* private fields */ }
Expand description

Struct used to parse entities from JSON.

Implementations§

Source§

impl<'e, 's, S: Schema> EntityJsonParser<'e, 's, S>

Source

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

pub fn from_json_str(&self, json: &str) -> Result<Entities, EntitiesError>

Parse an entities JSON file (in &str form) into an Entities object.

If the EntityJsonParser has a schema, this also adds Action entities declared in the schema.

Source

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.

Source

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.

Source

pub fn iter_from_json_str( &self, json: &str, ) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>

Parse an entities JSON file (in &str form) into an iterator over Entitys.

If the EntityJsonParser has a schema, this also adds Action entities declared in the schema.

Source

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.

Source

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.

Source

pub fn single_from_json_value( &self, value: Value, ) -> Result<Entity, EntitiesError>

Parse a single entity from an in-memory JSON value

Source

pub fn single_from_json_str( &self, src: impl AsRef<str>, ) -> Result<Entity, EntitiesError>

Parse a single entity from a JSON string

Source

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 + Schema> Clone for EntityJsonParser<'e, 's, S>

Source§

fn clone(&self) -> EntityJsonParser<'e, 's, S>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'e, 's, S: Debug + Schema> Debug for EntityJsonParser<'e, 's, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.