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) -> EventCode
pub fn from<S>(code: S) -> EventCode
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.
Trait Implementations§
Source§impl From<(Phenomenon, SignificanceLevel)> for EventCode
impl From<(Phenomenon, SignificanceLevel)> for EventCode
Source§fn from(value: (Phenomenon, SignificanceLevel)) -> EventCode
fn from(value: (Phenomenon, SignificanceLevel)) -> EventCode
Source§impl Ord for EventCode
impl Ord for EventCode
Source§impl PartialOrd for EventCode
impl PartialOrd for EventCode
impl Copy for EventCode
impl Eq for EventCode
impl StructuralPartialEq for EventCode
Auto Trait Implementations§
impl Freeze for EventCode
impl RefUnwindSafe for EventCode
impl Send for EventCode
impl Sync for EventCode
impl Unpin for EventCode
impl UnwindSafe for EventCode
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.