RuleContext

Struct RuleContext 

Source
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

Source

pub fn new() -> Self

Source

pub fn set_bool(&mut self, key: &'static str, value: bool)

Set a boolean value in the context

Source

pub fn set_int(&mut self, key: &'static str, value: i64)

Set an integer value in the context

Source

pub fn set_float(&mut self, key: &'static str, value: f64)

Set a float value in the context

Source

pub fn set_string(&mut self, key: &'static str, value: String)

Set a string value in the context

Source

pub fn set_bytes(&mut self, key: &'static str, value: Vec<u8>)

Set bytes in the context

Source

pub fn get_bool(&self, key: &'static str) -> RuleResult<bool>

Get a boolean value from the context

Source

pub fn get_int(&self, key: &'static str) -> RuleResult<i64>

Get an integer value from the context

Source

pub fn get_float(&self, key: &'static str) -> RuleResult<f64>

Get a float value from the context

Source

pub fn get_string(&self, key: &'static str) -> RuleResult<&str>

Get a string value from the context

Source

pub fn get_bytes(&self, key: &'static str) -> RuleResult<&[u8]>

Get bytes from the context

Source

pub fn contains_key(&self, key: &'static str) -> bool

Check if a key exists in the context

Source

pub fn remove(&mut self, key: &'static str) -> Option<ContextValue>

Remove a value from the context

Source

pub fn clear(&mut self)

Clear all values from the context

Trait Implementations§

Source§

impl Debug for RuleContext

Source§

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

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

impl Default for RuleContext

Source§

fn default() -> RuleContext

Returns the “default value” for a type. 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> 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, 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.