Expand description
A CAP alert message.
Variants
V1dot0(Alert)
A CAP v1.0 alert message
V1dot1(Alert)
A CAP v1.1 alert message
V1dot2(Alert)
A CAP v1.2 alert message
Implementations
sourceimpl Alert
impl Alert
sourcepub fn identifier(&self) -> &Id
pub fn identifier(&self) -> &Id
A unique identifier for this alert, assigned by the sender
sourcepub fn xml_namespace(&self) -> &'static str
pub fn xml_namespace(&self) -> &'static str
Returns the XML namespace corresponding to the encapsulated CAP alert version.
sourcepub fn into_latest(self) -> Alert
pub fn into_latest(self) -> Alert
Return this alert as the latest supported alert version, upgrading it as necessary.
CAP v1.2 is mostly a superset of earlier versions, with two exceptions:
- CAP <= v1.1
Resource
has an optionalmime_type
, whereas it’s required for CAP v1.2. This crate suppliesapplication/octet-stream
as a default if needed.
// let input: &str = /* CAP v1.0 appendix A.1 */;
let alert: oasiscap::Alert = input.parse().unwrap();
match &alert {
oasiscap::Alert::V1dot0(alert) => {
assert!(alert.info[0].resources[0].mime_type.is_none());
}
_ => unreachable!(),
}
let alert = alert.into_latest();
assert_eq!(alert.info[0].resources[0].mime_type, "application/octet-stream");
- CAP v1.0 has
Certainty::VeryLikely
, while later versions do not. The specification recommends substitutingCertainty::Likely
, so this crate does.
// let input: &str = /* CAP v1.0 appendix A.3 */;
let alert: oasiscap::Alert = input.parse().unwrap();
match &alert {
oasiscap::Alert::V1dot0(alert) => {
assert_eq!(alert.info[0].certainty, oasiscap::v1dot0::Certainty::VeryLikely);
}
_ => unreachable!(),
}
let alert = alert.into_latest();
assert_eq!(alert.info[0].certainty, oasiscap::v1dot2::Certainty::Likely);
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Alert
impl<'de> Deserialize<'de> for Alert
sourcefn 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 Alert
Auto Trait Implementations
impl RefUnwindSafe for Alert
impl Send for Alert
impl Sync for Alert
impl Unpin for Alert
impl UnwindSafe for Alert
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more