pub struct EventCode { /* private fields */ }Expand description
Decoded SAME event code
Represents the decoding of a three-character SAME event code,
like “RWT,” into a phenomenon and
significance.
-
The phenomenon describes what is occurring
-
The significance indicates the overall severity and/or how “noisy” or intrusive the alert should be.
EventCode are usually constructed via
MessageHeader::event() but may also
be directly created from string.
use sameplace::{EventCode, Phenomenon, SignificanceLevel};
let evt = EventCode::from("RWT");
assert_eq!(evt.phenomenon(), Phenomenon::RequiredWeeklyTest);
assert_eq!(evt.significance(), SignificanceLevel::Test);EventCode are Ord by their significance levels.
assert!(EventCode::from("RWT") < EventCode::from("SVA"));
assert!(EventCode::from("SVA") < EventCode::from("SVR"));The Display representation is a human-readable string representing
both phenomenon and significance.
assert_eq!(EventCode::from("SVA").to_string(), "Severe Thunderstorm Watch");The conversion from string is infallible, but invalid strings will result in an unrecognized message.
let watch = EventCode::from("??A");
assert!(watch.is_unrecognized());
assert_eq!(watch.significance(), SignificanceLevel::Watch);
assert_eq!(watch.to_string(), "Unrecognized Watch");
let unrec = EventCode::from("???");
assert!(unrec.is_unrecognized());
assert_eq!(unrec.significance(), SignificanceLevel::Unknown);
assert_eq!(unrec.to_string(), "Unrecognized Warning");If the phenomenon portion cannot be decoded, the third character
is parsed as a SignificanceLevel if possible. Unrecognized messages
are still valid, and clients are encouraged to handle them at their
significance level as normal.
Implementations§
Source§impl EventCode
impl EventCode
Sourcepub fn from<S>(code: S) -> Self
pub fn from<S>(code: S) -> Self
Parse from SAME code, like “RWT”
This type is usually constructed via
MessageHeader::event(), but
you can also construct them directly. This method decodes the
string representation of a three-character SAME event code,
like “RWT,” into a machine-readable event.
If the input code is not known to sameplace, is not in the
required format (i.e., three ASCII characters), or is otherwise
not valid, the output of
is_unrecognized() will be
true.
Sourcepub fn phenomenon(&self) -> Phenomenon
pub fn phenomenon(&self) -> Phenomenon
What is occurring?
Sourcepub fn significance(&self) -> SignificanceLevel
pub fn significance(&self) -> SignificanceLevel
What is the anticipated severity?
Sourcepub fn to_display_string(&self) -> String
pub fn to_display_string(&self) -> String
Human-readable string representation
Converts to a human-readable string, like “Required Monthly Test.”
Sourcepub fn is_test(&self) -> bool
pub fn is_test(&self) -> bool
True for test messages
Test messages do not represent real-life events or emergencies.
Sourcepub fn is_unrecognized(&self) -> bool
pub fn is_unrecognized(&self) -> bool
True if any part of the event code was unrecognized
Indicates that either the phenomenon or the significance could not be determined from the input SAME code.
Unrecognized messages are still valid, and clients are encouraged to handle them at their significance level as normal.