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
impl Context
Sourcepub fn logging(path: impl AsRef<Path>, level: Level) -> CcsResult<Self>
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
impl Context
Sourcepub fn from_str_without_tracing(ccs: impl AsRef<str>) -> AstResult<Self>
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
impl Context
Sourcepub fn load_with_tracer(
path: impl AsRef<Path>,
tracer: impl PropertyTracer + 'static,
) -> CcsResult<Self>
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.
Sourcepub fn load(
path: impl AsRef<Path>,
resolver: impl ImportResolver,
tracer: impl PropertyTracer + 'static,
) -> CcsResult<Self>
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.
Sourcepub fn from_str(
ccs: impl AsRef<str>,
resolver: impl ImportResolver,
tracer: impl PropertyTracer + 'static,
) -> AstResult<Self>
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.
Sourcepub fn constrain(&self, constraint: impl AsKey) -> Self
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 = zthe 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 = zthe 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");Sourcepub fn get(&self, prop: impl AsRef<str>) -> SearchResult<PropertyValue>
pub fn get(&self, prop: impl AsRef<str>) -> SearchResult<PropertyValue>
Retrieves the value of a property from the current context, if possible
Sourcepub fn get_value(&self, prop: impl AsRef<str>) -> SearchResult<PersistentStr>
pub fn get_value(&self, prop: impl AsRef<str>) -> SearchResult<PersistentStr>
Helper function for Context::get to get PropertyValue::value
Sourcepub fn get_type<T: TypedProperty>(
&self,
prop: impl AsRef<str>,
) -> ContextResult<T>
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);Sourcepub fn get_or<T: TypedProperty>(&self, prop: impl AsRef<str>, default: T) -> T
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");Sourcepub fn get_or_default<T: TypedProperty + Default>(
&self,
prop: impl AsRef<str>,
) -> T
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"), "");Sourcepub fn get_current_context(&self) -> DisplayContext
pub fn get_current_context(&self) -> DisplayContext
Retrieves the current context’s queue of applied constraints, in the order they were applied
Sourcepub fn get_dag_stats(&self) -> DagStats
pub fn get_dag_stats(&self) -> DagStats
Retrieves information about the DAG that underpins the activation algorithm
Sourcepub fn dag_as_dot_str(&self) -> String
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§
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
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