pub struct Component { /* private fields */ }
Expand description
Indicates what (program/functionality) a Message
is referring to.
This helps route messages to the relevant location, as well
as control their severity.
§Examples
use rnotifylib::message::component::Component;
let db_backup_component = Component::from("database/backup");
let db_uptime_component = Component::from("database/uptime");
let db_component = Component::from("database");
// Both of these are children of the db component - Hence destinations that subscribe
// to the database component will receive both backup and uptime messages.
assert!(db_backup_component.is_child_of(&db_component), "backup component should be child of db component");
assert!(db_uptime_component.is_child_of(&db_component), "uptime component should be child of db component");
// Additionally, the database component is a "child" of itself,
// Therefore messages with the "database" component will be sent to places that listen for the database component
assert!(db_component.is_child_of(&db_component));
Implementations§
Source§impl Component
impl Component
Sourcepub fn is_child_of(&self, parent: &Component) -> bool
pub fn is_child_of(&self, parent: &Component) -> bool
Gets whether this is a child of the given parent.
use rnotifylib::message::component::Component;
// Two child components
let db_backup_component = Component::from("database/backup");
let db_uptime_component = Component::from("database/uptime");
// Parent database component
let db_component = Component::from("database");
// Child components of the same thing are children.
assert!(db_backup_component.is_child_of(&db_component), "backup component should be child of db component");
assert!(db_uptime_component.is_child_of(&db_component), "uptime component should be child of db component");
// And the parent is a child of itself.
assert!(db_component.is_child_of(&db_component), "Should be a child of itself");
// But the parent is not a child of the child.
assert!(!db_component.is_child_of(&db_backup_component), "database component should not be a child of the backup sub-component");
let website_component = Component::from("website");
let website_backend_component = Component::from("website/component");
// Unrelated components are not children of each other
assert!(!db_component.is_child_of(&website_backend_component), "db component shouldn't be a child of website backend component");
assert!(!db_component.is_child_of(&website_component), "db component shouldn't be a child of the website component");
assert!(!db_backup_component.is_child_of(&website_component), "db backup component shouldn't be a child of the website component");
assert!(!db_backup_component.is_child_of(&website_backend_component), "db backup shouldn't be a child of the website backup component");
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Component
impl<'de> Deserialize<'de> for Component
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
impl StructuralPartialEq for Component
Auto Trait Implementations§
impl Freeze for Component
impl RefUnwindSafe for Component
impl Send for Component
impl Sync for Component
impl Unpin for Component
impl UnwindSafe for Component
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