cedar_policy_core::entities::json

Enum CedarValueJson

Source
pub enum CedarValueJson {
    ExprEscape {
        __expr: SmolStr,
    },
    EntityEscape {
        __entity: TypeAndId,
    },
    ExtnEscape {
        __extn: FnAndArg,
    },
    Bool(bool),
    Long(i64),
    String(SmolStr),
    Set(Vec<CedarValueJson>),
    Record(JsonRecord),
    Null,
}
Expand description

The canonical JSON representation of a Cedar value. Many Cedar values have a natural one-to-one mapping to and from JSON values. Cedar values of some types, like entity references or extension values, cannot easily be represented in JSON and thus are represented using the __entity, or __extn escapes.

For example, this is the JSON format for attribute values expected by EntityJsonParser, when schema-based parsing is not used.

Variants§

§

ExprEscape

The __expr escape has been removed, but is still reserved in order to throw meaningful errors.

Fields

§__expr: SmolStr

Contents, will be ignored and an error is thrown when attempting to parse this

§

EntityEscape

Special JSON object with single reserved “__entity” key: the following item should be a JSON object of the form { "type": "xxx", "id": "yyy" }. This escape is necessary for entity references.

Fields

§__entity: TypeAndId

JSON object containing the entity type and ID

§

ExtnEscape

Special JSON object with single reserved “__extn” key: the following item should be a JSON object of the form { "fn": "xxx", "arg": "yyy" }. This escape is necessary for extension values.

Fields

§__extn: FnAndArg

JSON object containing the extension-constructor call

§

Bool(bool)

JSON bool => Cedar bool

§

Long(i64)

JSON int => Cedar long (64-bit signed integer)

§

String(SmolStr)

JSON string => Cedar string

§

Set(Vec<CedarValueJson>)

JSON list => Cedar set; can contain any CedarValueJsons, even heterogeneously

§

Record(JsonRecord)

JSON object => Cedar record; must have string keys, but values can be any CedarValueJsons, even heterogeneously

§

Null

JSON null, which is never valid, but we put this here in order to provide a better error message.

Implementations§

Source§

impl CedarValueJson

Source

pub fn uid(euid: &EntityUID) -> Self

Encode the given EntityUID as a CedarValueJson

Source

pub fn into_expr( self, ctx: impl Fn() -> JsonDeserializationErrorContext + Clone, ) -> Result<RestrictedExpr, JsonDeserializationError>

Convert this CedarValueJson into a Cedar “restricted expression”

Source

pub fn from_expr( expr: BorrowedRestrictedExpr<'_>, ) -> Result<Self, JsonSerializationError>

Convert a Cedar “restricted expression” into a CedarValueJson.

Source

pub fn from_value(value: Value) -> Result<Self, JsonSerializationError>

Convert a Cedar value into a CedarValueJson.

Only throws errors in two cases:

  1. value is (or contains) a record with a reserved key such as “__entity”
  2. value is (or contains) an extension value, and the argument to the extension constructor that produced that extension value can’t itself be converted to CedarJsonValue. (Either because that argument falls into one of these two cases itself, or because the argument is a nontrivial residual.)
Source

pub fn from_valuekind(value: ValueKind) -> Result<Self, JsonSerializationError>

Convert a Cedar ValueKind into a CedarValueJson.

For discussion of when this throws errors, see notes on from_value.

Source

pub fn from_lit(lit: Literal) -> Self

Convert a Cedar literal into a CedarValueJson.

Source

pub fn sub_entity_literals( self, mapping: &BTreeMap<EntityUID, EntityUID>, ) -> Result<Self, JsonDeserializationError>

Substitute entity literals

Trait Implementations§

Source§

impl Clone for CedarValueJson

Source§

fn clone(&self) -> CedarValueJson

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 Debug for CedarValueJson

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CedarValueJson

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for CedarValueJson

Source§

fn eq(&self, other: &CedarValueJson) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CedarValueJson

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for CedarValueJson

Source§

impl StructuralPartialEq for CedarValueJson

Auto Trait Implementations§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,