Enum Context

Source
pub enum Context {
    Value(Arc<BTreeMap<SmolStr, Value>>),
    RestrictedResidual(Arc<BTreeMap<SmolStr, Expr>>),
}
Expand description

Context field of a Request

Variants§

§

Value(Arc<BTreeMap<SmolStr, Value>>)

The context is a concrete value.

§

RestrictedResidual(Arc<BTreeMap<SmolStr, Expr>>)

The context is a residual expression, containing some unknown value in the record attributes. INVARIANT(restricted): Each Expr in this map must be a RestrictedExpr. INVARIANT(unknown): At least one Expr must contain an unknown.

Implementations§

Source§

impl Context

Source

pub fn empty() -> Self

Create an empty Context

Source

pub fn from_expr( expr: BorrowedRestrictedExpr<'_>, extensions: &Extensions<'_>, ) -> Result<Self, ContextCreationError>

Create a Context from a RestrictedExpr, which must be a Record.

extensions provides the Extensions which should be active for evaluating the RestrictedExpr.

Source

pub fn from_pairs( pairs: impl IntoIterator<Item = (SmolStr, RestrictedExpr)>, extensions: &Extensions<'_>, ) -> Result<Self, ContextCreationError>

Create a Context from a map of key to RestrictedExpr, or a Vec of (key, RestrictedExpr) pairs, or any other iterator of (key, RestrictedExpr) pairs

extensions provides the Extensions which should be active for evaluating the RestrictedExpr.

Source

pub fn from_json_str( json: &str, ) -> Result<Self, ContextJsonDeserializationError>

Create a Context from a string containing JSON (which must be a JSON object, not any other JSON type, or you will get an error here). JSON here must use the __entity and __extn escapes for entity references, extension values, etc.

For schema-based parsing, use ContextJsonParser.

Source

pub fn from_json_value( json: Value, ) -> Result<Self, ContextJsonDeserializationError>

Create a Context from a serde_json::Value (which must be a JSON object, not any other JSON type, or you will get an error here). JSON here must use the __entity and __extn escapes for entity references, extension values, etc.

For schema-based parsing, use ContextJsonParser.

Source

pub fn from_json_file( json: impl Read, ) -> Result<Self, ContextJsonDeserializationError>

Create a Context from a JSON file. The JSON file must contain a JSON object, not any other JSON type, or you will get an error here. JSON here must use the __entity and __extn escapes for entity references, extension values, etc.

For schema-based parsing, use ContextJsonParser.

Source

pub fn num_keys(&self) -> usize

Get the number of keys in this Context.

Source

pub fn substitute( self, mapping: &HashMap<SmolStr, Value>, ) -> Result<Self, EvaluationError>

Substitute unknowns with concrete values in this context. If this is already a Context::Value, then this returns self unchanged and will not error. Otherwise delegate to Expr::substitute.

Trait Implementations§

Source§

impl BoundedDisplay for Context

Source§

fn fmt(&self, f: &mut impl Write, n: Option<usize>) -> Result

Write self to the writer f, truncating set elements or key-value pairs if necessary based on n
Source§

fn fmt_bounded(&self, f: &mut impl Write, n: usize) -> Result

Convenience method, equivalent to fmt() with n as Some. Read more
Source§

fn fmt_unbounded(&self, f: &mut impl Write) -> Result

Convenience method, equivalent to fmt() with n as None. Read more
Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a duplicate 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 Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Context

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

impl Display for Context

Source§

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

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

impl From<Context> for PartialValue

Source§

fn from(ctx: Context) -> PartialValue

Converts to this type from the input type.
Source§

impl From<Context> for RestrictedExpr

Source§

fn from(value: Context) -> Self

Converts to this type from the input type.
Source§

impl IntoIterator for Context

Source§

type Item = (SmolStr, RestrictedExpr)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Context

Source§

fn eq(&self, other: &Context) -> 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 Eq for Context

Source§

impl StructuralPartialEq for Context

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> BoundedToString for T
where T: BoundedDisplay,

Source§

fn to_string(&self, n: Option<usize>) -> String

Convert self to a String, truncating set elements or key-value pairs if necessary based on n
Source§

fn to_string_bounded(&self, n: usize) -> String

Convenience method, equivalent to to_string() with n as Some. Read more
Source§

fn to_string_unbounded(&self) -> String

Convenience method, equivalent to to_string() with n as None. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.