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 duplicate 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 for MessageCondition
impl PartialEq for MessageCondition
Source§impl Serialize for MessageCondition
impl Serialize for MessageCondition
impl StructuralPartialEq for MessageCondition
Auto Trait Implementations§
impl Freeze for MessageCondition
impl RefUnwindSafe for MessageCondition
impl Send for MessageCondition
impl Sync for MessageCondition
impl Unpin for MessageCondition
impl UnwindSafe for MessageCondition
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