pub struct Subject { /* private fields */ }Expand description
A structured subject made of typed Segments.
A subject can be concrete (no wildcards) or a pattern (with *
and/or >). The wire format is bincode-encoded bytes.
// Concrete:
let s = Subject::new().str("job").int(42).str("logs");
assert_eq!(s.to_string(), "job.42.logs");
// Pattern:
let p = Subject::new().str("job").any().str("logs");
assert_eq!(p.to_string(), "job.*.logs");
// Roundtrip through bytes:
let bytes = s.to_bytes();
let s2 = Subject::from_bytes(&bytes).unwrap();
assert_eq!(s, s2);Implementations§
Source§impl Subject
impl Subject
Sourcepub fn str(self, s: impl Into<String>) -> Self
pub fn str(self, s: impl Into<String>) -> Self
Append a string segment.
§Panics
Panics if the string is empty, contains reserved characters, or if
the subject already ends with >.
Sourcepub fn rest(self) -> Self
pub fn rest(self) -> Self
Append a multi-segment wildcard (>). Must be the last segment.
§Panics
Panics if > already exists in the subject.
Sourcepub fn is_concrete(&self) -> bool
pub fn is_concrete(&self) -> bool
true if the subject contains no wildcards.
Concrete subjects enable fast-path exact-match routing in the broker.
Sourcepub fn is_pattern(&self) -> bool
pub fn is_pattern(&self) -> bool
true if the subject contains any wildcard segment.
Sourcepub fn matches(&self, concrete: &Subject) -> bool
pub fn matches(&self, concrete: &Subject) -> bool
Test whether a concrete subject matches this pattern.
If self is concrete, this is an equality check.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
Deserialize from bincode bytes.
Sourcepub fn from_module_path(module_path: &str, type_name: &str) -> Self
pub fn from_module_path(module_path: &str, type_name: &str) -> Self
Build a Subject from module_path!() and a type name.
Splits the module path on :: and appends each part as a string
segment, then appends the type name.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Subject
impl<'de> Deserialize<'de> for Subject
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>,
Source§impl From<&str> for Subject
impl From<&str> for Subject
Source§fn from(s: &str) -> Self
fn from(s: &str) -> Self
Parse a dot-separated string. * becomes Segment::Any,
> becomes Segment::Rest, integers become Segment::Int,
everything else is Segment::Str.