Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

The primary representation of a CCS search state

Typically you’ll want the Context::logging constructor, or (if not using the log feature), the Context::load_with_tracer. See PropertyTracer for more information.

In tests, you may want Context::from_str with test implementations of resolvers and tracers.

Implementations§

Source§

impl Context

Source

pub fn logging(path: impl AsRef<Path>, level: Level) -> CcsResult<Self>

Loads a CCS file, and creates a context that logs when and where properties are found

Uses the RelativePathResolver

See PropertyTracer and LogTracer for more.

Source§

impl Context

Source

pub fn from_str_without_tracing(ccs: impl AsRef<str>) -> AstResult<Self>

Creates a context that does not trace when or where properties are found

Will use an empty ImportResolver, that just skips over import statements. To provide a different ImportResolver, use Context::from_str

Generally this is most useful in tests.

Source§

impl Context

Source

pub fn load_with_tracer( path: impl AsRef<Path>, tracer: impl PropertyTracer + 'static, ) -> CcsResult<Self>

Loads a CCS file, and creates a context with the provided tracer

Uses the RelativePathResolver

See PropertyTracer for more.

Source

pub fn load( path: impl AsRef<Path>, resolver: impl ImportResolver, tracer: impl PropertyTracer + 'static, ) -> CcsResult<Self>

Loads a CCS file, and creates a context with the provided import resolver and tracer

See ImportResolver PropertyTracer for more.

Source

pub fn from_str( ccs: impl AsRef<str>, resolver: impl ImportResolver, tracer: impl PropertyTracer + 'static, ) -> AstResult<Self>

Creates a context from a provided CCS string, using the provided import resolver and tracer

See ImportResolver PropertyTracer for more.

Mostly useful for tests.

Source

pub fn constrain(&self, constraint: impl AsKey) -> Self

Create a new context augmented with the given constraint

§Example: Key-only constraint

Given the following CCS:

module : a = z

the property a can be retrieved through constraining with "module":

assert!(context.get_value("a").is_err());

let x: &str = &context.constrain("module").get_value("a")?;
assert_eq!(x, "z");
§Example: Key-value constraint

Given the following CCS;

env.prod : a = z

the property a can be retrieved through constraining with ("env", "prod"):

assert!(context.constrain("env").get_value("a").is_err());

let x: &str = &context.constrain(("env", "prod")).get_value("a")?;
assert_eq!(x, "z");
Source

pub fn get(&self, prop: impl AsRef<str>) -> SearchResult<PropertyValue>

Retrieves the value of a property from the current context, if possible

Source

pub fn get_value(&self, prop: impl AsRef<str>) -> SearchResult<PersistentStr>

Helper function for Context::get to get PropertyValue::value

Source

pub fn get_type<T: TypedProperty>( &self, prop: impl AsRef<str>, ) -> ContextResult<T>

Helper for the ever-common “get and convert” pattern

context.get_type::<T>(prop) is basically equivalent to context.get(prop)?.to_type::<T>()

assert_eq!(context.get_type::<i32>("x")?, 42);
Source

pub fn get_or<T: TypedProperty>(&self, prop: impl AsRef<str>, default: T) -> T

Get a typed value, or provide the default if it cannot be found

assert_eq!(&context.get_or("undefined", "default_val".to_string()), "default_val");
Source

pub fn get_or_default<T: TypedProperty + Default>( &self, prop: impl AsRef<str>, ) -> T

Get a typed value, or return the type’s Default value

assert_eq!(&context.get_or_default::<String>("undefined"), "");
Source

pub fn get_current_context(&self) -> DisplayContext

Retrieves the current context’s queue of applied constraints, in the order they were applied

Source

pub fn get_dag_stats(&self) -> DagStats

Retrieves information about the DAG that underpins the activation algorithm

Source

pub fn dag_as_dot_str(&self) -> String

Turns the underlying DAG into a DOT string, which can be used for visualization.

Requires the dot feature

Trait Implementations§

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

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, dest: *mut u8)

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