Struct rnotifylib::destination::message_condition::MessageCondition
source · pub struct MessageCondition { /* private fields */ }Expand description
A filter for a Message
Implementations§
source§impl MessageCondition
impl MessageCondition
sourcepub fn new(
component: Option<Component>,
min_level: Level,
max_level: Level
) -> Self
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
sourcepub fn of_component(component: Component) -> Self
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");sourcepub fn of_min(min_level: Level) -> Self
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")
sourcepub fn of_max(max_level: Level) -> Self
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")
pub fn matches(&self, m: &Message) -> bool
Trait Implementations§
source§impl Clone for MessageCondition
impl Clone for MessageCondition
source§fn clone(&self) -> MessageCondition
fn clone(&self) -> MessageCondition
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for MessageCondition
impl Debug for MessageCondition
source§impl Default for MessageCondition
impl Default for MessageCondition
source§fn default() -> Self
fn default() -> Self
The default MessageCondition matches all messages.
source§impl<'de> Deserialize<'de> for MessageCondition
impl<'de> Deserialize<'de> for MessageCondition
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl PartialEq<MessageCondition> for MessageCondition
source§fn eq(&self, other: &MessageCondition) -> bool
fn eq(&self, other: &MessageCondition) -> bool
This method tests for
self and other values to be equal, and is used
by ==.