Trait sequoia_openpgp::packet::Any

source ·
pub trait Any<T>: Sealed {
    // Required methods
    fn downcast(self) -> Result<T, Packet>;
    fn downcast_ref(&self) -> Option<&T>;
    fn downcast_mut(&mut self) -> Option<&mut T>;
}
Expand description

Convenient downcasting from Packets to Packet Bodies.

This trait offers functionality similar to std::any::Any, hence the name.

§Sealed trait

This trait is sealed and cannot be implemented for types outside this crate. Therefore it can be extended in a non-breaking way.

Required Methods§

source

fn downcast(self) -> Result<T, Packet>

Attempts to downcast to T, returning the packet if it fails.

§Examples
let p: Packet = Marker::default().into();
let m: Marker = p.downcast().unwrap();
source

fn downcast_ref(&self) -> Option<&T>

Attempts to downcast to &T, returning None if it fails.

§Examples
let p: Packet = Marker::default().into();
let m: &Marker = p.downcast_ref().unwrap();
source

fn downcast_mut(&mut self) -> Option<&mut T>

Attempts to downcast to &mut T, returning None if it fails.

§Examples
let mut p: Packet = Marker::default().into();
let m: &mut Marker = p.downcast_mut().unwrap();

Implementors§