pub struct Extension { /* private fields */ }Expand description
The Extension struct is used to store the “header” information for an extension.
This information is added at the start of each extension data and it is used to determine the type of extension and the length of the extension data.
Implementations§
Source§impl Extension
impl Extension
pub const LEN: usize
pub fn new( extension_type: ExtensionType, length: u32, boundary: u32, ) -> Extension
Sourcepub fn try_extension_type(&self) -> Result<ExtensionType, Error>
pub fn try_extension_type(&self) -> Result<ExtensionType, Error>
Try to get the extension type.
The extension type is stored as a u32 on the acccount data. This method tries to
perform the conversion to an ExtensionType and returns an error if the conversion
fails – e.g., the u32 value is not a valid extension type. This can happen when
a new extension type is added and an older version of the library is used.
Sourcepub fn extension_type(&self) -> ExtensionType
pub fn extension_type(&self) -> ExtensionType
Returns the extension type.
This method is similar to try_extension_type, but panics if the u32 value on the
account data cannot be converted to an ExtensionType.
pub fn set_extension_type(&mut self, extension_type: ExtensionType)
pub fn length(&self) -> u32
pub fn set_length(&mut self, length: u32)
Sourcepub fn boundary(&self) -> u32
pub fn boundary(&self) -> u32
Returns the boundary of the extension.
The boundary is the number of bytes from the start of the extension to the start of the next extension. This is used specify any padding that may be required to maintain byte alignment.
Note that the boundary might be larger than the length of the extension data.
pub fn set_boundary(&mut self, boundary: u32)
Sourcepub fn get<'a, T>(data: &'a [u8]) -> Option<T>where
T: ExtensionData<'a>,
pub fn get<'a, T>(data: &'a [u8]) -> Option<T>where
T: ExtensionData<'a>,
Returns the extension data of a given type.
This function expects a slice of bytes of extension data only and it will return the first
extension of the given type; if the extension type is not found, None is returned.
Sourcepub fn get_mut<'a, T>(data: &'a mut [u8]) -> Option<T>where
T: ExtensionDataMut<'a>,
pub fn get_mut<'a, T>(data: &'a mut [u8]) -> Option<T>where
T: ExtensionDataMut<'a>,
Returns a mutable reference to the extension data of a given type.
This function expects a slice of bytes of extension data only and it will return the first
extension of the given type; if the extension type is not found, None is returned.
Trait Implementations§
impl Copy for Extension
impl Pod for Extension
Auto Trait Implementations§
impl Freeze for Extension
impl RefUnwindSafe for Extension
impl Send for Extension
impl Sync for Extension
impl Unpin for Extension
impl UnsafeUnpin for Extension
impl UnwindSafe for Extension
Blanket Implementations§
impl<T> AnyBitPattern for Twhere
T: Pod,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more