pub struct RuleContext { /* private fields */ }Expand description
RuleContext is a struct that holds the context of the rule.
It provides type-safe access to values without using dyn Any.
Example:
use dredd_rs::rule::*;
let mut rule_context = RuleContext::new();
rule_context.set_bool("test", true);
let test = rule_context.get_bool("test");Implementations§
Source§impl RuleContext
impl RuleContext
pub fn new() -> Self
Sourcepub fn set_string(&mut self, key: &'static str, value: String)
pub fn set_string(&mut self, key: &'static str, value: String)
Set a string value in the context
Sourcepub fn get_bool(&self, key: &'static str) -> RuleResult<bool>
pub fn get_bool(&self, key: &'static str) -> RuleResult<bool>
Get a boolean value from the context
Sourcepub fn get_int(&self, key: &'static str) -> RuleResult<i64>
pub fn get_int(&self, key: &'static str) -> RuleResult<i64>
Get an integer value from the context
Sourcepub fn get_float(&self, key: &'static str) -> RuleResult<f64>
pub fn get_float(&self, key: &'static str) -> RuleResult<f64>
Get a float value from the context
Sourcepub fn get_string(&self, key: &'static str) -> RuleResult<&str>
pub fn get_string(&self, key: &'static str) -> RuleResult<&str>
Get a string value from the context
Sourcepub fn get_bytes(&self, key: &'static str) -> RuleResult<&[u8]>
pub fn get_bytes(&self, key: &'static str) -> RuleResult<&[u8]>
Get bytes from the context
Sourcepub fn contains_key(&self, key: &'static str) -> bool
pub fn contains_key(&self, key: &'static str) -> bool
Check if a key exists in the context
Sourcepub fn remove(&mut self, key: &'static str) -> Option<ContextValue>
pub fn remove(&mut self, key: &'static str) -> Option<ContextValue>
Remove a value from the context
Trait Implementations§
Source§impl Debug for RuleContext
impl Debug for RuleContext
Source§impl Default for RuleContext
impl Default for RuleContext
Source§fn default() -> RuleContext
fn default() -> RuleContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RuleContext
impl RefUnwindSafe for RuleContext
impl Send for RuleContext
impl Sync for RuleContext
impl Unpin for RuleContext
impl UnwindSafe for RuleContext
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
Mutably borrows from an owned value. Read more