pub struct Context { /* private fields */ }
Expand description
The request context used when evaluating an Aspen policy.
Context structures are immutable.
Implementations§
Source§impl Context
impl Context
Sourcepub fn builder() -> ContextBuilder
pub fn builder() -> ContextBuilder
Returns a new ContextBuilder for building a Context.
Sourcepub fn session_data(&self) -> &SessionData
pub fn session_data(&self) -> &SessionData
Returrns the session data associated with the request.
Sourcepub fn matcher<T: AsRef<str>>(
&self,
s: T,
pv: PolicyVersion,
case_insensitive: bool,
) -> Result<Regex, AspenError>
pub fn matcher<T: AsRef<str>>( &self, s: T, pv: PolicyVersion, case_insensitive: bool, ) -> Result<Regex, AspenError>
Creates a Regex from the given string pattern and policy version.
If case_insensitive
is true
, the returned Regex will be case insensitive.
Wildcards are converted to their regular expression equivalents. If the policy version is
PolicyVersion::V2012_10_17 or later, variables are substituted and regex-escaped as necessary. The special
variables ${*}
, ${$}
, and ${?}
are converted to literal *
, $
, and ?
characters, respectively, then
regex-escaped.
§Errors
If the string contains a malformed variable reference and PolicyVersion::V2012_10_17 or later is used, AspenError::InvalidSubstitution is returned.
Sourcepub fn subst_vars_plain(&self, s: &str) -> Result<String, AspenError>
pub fn subst_vars_plain(&self, s: &str) -> Result<String, AspenError>
Substitutes variables from the given string, returning the resulting string.
§Errors
If the string contains a malformed variable reference and PolicyVersion::V2012_10_17 or later is used, AspenError::InvalidSubstitution is returned.