pub struct EventName(/* private fields */);Expand description
A validated event: value.
A Cow rather than an Arc<str> for one reason that turned out to
decide the design: Arc::from is not const, so an Arc-backed name
cannot be a const, and the two names the legacy transport is defined by
are exactly the kind of thing that should be a constant rather than a value
built at first use. Cow::Borrowed is const-constructible, so the two
names the specification names cost nothing and compare without a pointer
chase, while a name that arrived from a peer is owned and costs one
allocation — which is right, because a peer’s name is not known ahead of
time and there is nothing to borrow it from.
Borrowed is safe here for the same reason it is safe anywhere: a &'static str has no lifetime to shorten, and from_str is the only constructor
that produces a Borrowed variant.
Implementations§
Trait Implementations§
impl Eq for EventName
Source§impl FromStr for EventName
impl FromStr for EventName
Source§fn from_str(value: &str) -> Result<Self, Self::Err>
fn from_str(value: &str) -> Result<Self, Self::Err>
Parses a name, refusing the one thing that would inject a field.
CR and LF are both rejected, and both must be: the encoder’s line terminator is LF, but a conformant reader also treats a lone CR as a break, so a name holding a CR reads as two fields on a reader that the writer did not have in mind. Rejecting only LF would leave that reader injectable.
A colon is not rejected. The grammar makes the value the rest of the
line, so a:b is a legal name and a client comparing it to b has a
bug, not a server that corrupted it.
§Errors
EventNameError::Empty for an empty value, and
EventNameError::LineTerminator for one containing CR or LF.