Struct sequoia_openpgp::parse::map::Field
source · pub struct Field<'a> { /* private fields */ }
Expand description
Implementations§
source§impl<'a> Field<'a>
impl<'a> Field<'a>
sourcepub fn name(&self) -> &'a str
pub fn name(&self) -> &'a str
Returns the name of the field.
Note: The returned names are for display purposes only and may change in the future.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::parse::{Parse, PacketParserBuilder};
let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.";
let pp = PacketParserBuilder::from_bytes(message_data)?
.map(true) // Enable mapping.
.buffer_unread_content() // For the packet body.
.build()?
.expect("One packet, not EOF");
let map = pp.map().expect("Mapping is enabled");
assert_eq!(map.iter().nth(0).unwrap().name(), "CTB");
assert_eq!(map.iter().nth(1).unwrap().name(), "length");
assert_eq!(map.iter().nth(2).unwrap().name(), "format");
assert_eq!(map.iter().nth(3).unwrap().name(), "filename_len");
assert_eq!(map.iter().nth(4).unwrap().name(), "date");
assert_eq!(map.iter().nth(5).unwrap().name(), "body");
assert!(map.iter().nth(6).is_none());
sourcepub fn offset(&self) -> usize
pub fn offset(&self) -> usize
Returns the offset of the field in the packet.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::parse::{Parse, PacketParserBuilder};
let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.";
let pp = PacketParserBuilder::from_bytes(message_data)?
.map(true) // Enable mapping.
.buffer_unread_content() // For the packet body.
.build()?
.expect("One packet, not EOF");
let map = pp.map().expect("Mapping is enabled");
assert_eq!(map.iter().nth(0).unwrap().offset(), 0);
assert_eq!(map.iter().nth(1).unwrap().offset(), 1);
assert_eq!(map.iter().nth(2).unwrap().offset(), 2);
assert_eq!(map.iter().nth(3).unwrap().offset(), 3);
assert_eq!(map.iter().nth(4).unwrap().offset(), 4);
assert_eq!(map.iter().nth(5).unwrap().offset(), 8);
assert!(map.iter().nth(6).is_none());
sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Returns the value of the field.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::parse::{Parse, PacketParserBuilder};
let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.";
let pp = PacketParserBuilder::from_bytes(message_data)?
.map(true) // Enable mapping.
.buffer_unread_content() // For the packet body.
.build()?
.expect("One packet, not EOF");
let map = pp.map().expect("Mapping is enabled");
assert_eq!(map.iter().nth(0).unwrap().as_bytes(), &[0xcb]);
assert_eq!(map.iter().nth(1).unwrap().as_bytes(), &[0x12]);
assert_eq!(map.iter().nth(2).unwrap().as_bytes(), "t".as_bytes());
assert_eq!(map.iter().nth(3).unwrap().as_bytes(), &[0x00]);
assert_eq!(map.iter().nth(4).unwrap().as_bytes(),
&[0x00, 0x00, 0x00, 0x00]);
assert_eq!(map.iter().nth(5).unwrap().as_bytes(),
"Hello world.".as_bytes());
assert!(map.iter().nth(6).is_none());
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Field<'a>
impl<'a> RefUnwindSafe for Field<'a>
impl<'a> Send for Field<'a>
impl<'a> Sync for Field<'a>
impl<'a> Unpin for Field<'a>
impl<'a> UnwindSafe for Field<'a>
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)