pub struct MessageCondition { /* private fields */ }
Expand description

A filter for a Message

Implementations§

source§

impl MessageCondition

source

pub fn new(
    component: Option<Component>,
    min_level: Level,
    max_level: Level
) -> Self

Creates a new MessageCondition, that requires ALL of the conditions to be met. For each parameter, see the individual documentation

source

pub fn of_component(component: Component) -> Self

If present, then Messages must be a child of (or same as) this component as per Component::is_child_of

use rnotifylib::destination::message_condition::MessageCondition;
use rnotifylib::message::builder::MessageBuilder;
use rnotifylib::message::component::Component;
use rnotifylib::message::Message;

let condition_component = Component::from("database/backup");
let condition = MessageCondition::of_component(condition_component);

fn make_message(component: &str) -> Message {
    let mut message_builder = MessageBuilder::new();
    message_builder.component(Component::from(component));
    message_builder.build()
}

assert!(condition.matches(&make_message("database/backup")), "Should match itself");

assert!(condition.matches(&make_message("database/backup/table1")), "Should match child");
assert!(condition.matches(&make_message("database/backup/table2")), "Should match child");

assert!(!condition.matches(&make_message("database/uptime")), "Should not match - not to do with database backup");
assert!(!condition.matches(&make_message("fish_and_chip_shop/fries")), "Should not match - not to do with database");
source

pub fn of_min(min_level: Level) -> Self

Messages with a Level below this will not match this filter

use rnotifylib::destination::message_condition::MessageCondition;
use rnotifylib::message::builder::MessageBuilder;
use rnotifylib::message::Level;

let condition = MessageCondition::of_min(Level::Warn);

let mut message_builder = MessageBuilder::new();

message_builder.level(Level::Info);
let message = message_builder.build_clone();
assert!(!condition.matches(&message), "Info < Warn, so should not let through");

message_builder.level(Level::Warn);
let message = message_builder.build_clone();
assert!(condition.matches(&message), "Warn >= Warn, so should be let through");

message_builder.level(Level::Error);
let message = message_builder.build_clone();
assert!(condition.matches(&message), "Error >= Warn, so should let through")
source

pub fn of_max(max_level: Level) -> Self

Messages with a Level above this will not match this filter

use rnotifylib::destination::message_condition::MessageCondition;
use rnotifylib::message::builder::MessageBuilder;
use rnotifylib::message::Level;

let condition = MessageCondition::of_max(Level::Warn);

let mut message_builder = MessageBuilder::new();

message_builder.level(Level::Info);
let message = message_builder.build_clone();
assert!(condition.matches(&message), "Info <= Warn, so should let through");

message_builder.level(Level::Warn);
let message = message_builder.build_clone();
assert!(condition.matches(&message), "Warn <= Warn, so should be let through");

message_builder.level(Level::Error);
let message = message_builder.build_clone();
assert!(!condition.matches(&message), "Error > Warn,  so should not let through")
source

pub fn matches(&self, m: &Message) -> bool

Trait Implementations§

source§

impl Clone for MessageCondition

source§

fn clone(&self) -> MessageCondition

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MessageCondition

source§

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

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

impl Default for MessageCondition

source§

fn default() -> Self

The default MessageCondition matches all messages.

source§

impl<'de> Deserialize<'de> for MessageCondition

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
    __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<MessageCondition> for MessageCondition

source§

fn eq(&self, other: &MessageCondition) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for MessageCondition

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where
    __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for MessageCondition

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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> Serialize for Twhere
    T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

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 Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere
    T: for<'de> Deserialize<'de>,