Trait octseq::octets::OctetsFrom

source ·
pub trait OctetsFrom<Source>: Sized {
    type Error: Into<ShortBuf>;

    // Required method
    fn try_octets_from(source: Source) -> Result<Self, Self::Error>;

    // Provided method
    fn octets_from(source: Source) -> Self
       where Self::Error: Into<Infallible> { ... }
}
Expand description

Convert a type from one octets type to another.

This trait allows creating a value of a type that is generic over an octets sequence from an identical value using a different type of octets sequence.

This is different from just From in that the conversion may fail if the source sequence is longer than the space available for the target type.

Required Associated Types§

Required Methods§

source

fn try_octets_from(source: Source) -> Result<Self, Self::Error>

Performs the conversion.

Provided Methods§

source

fn octets_from(source: Source) -> Self
where Self::Error: Into<Infallible>,

Performs an infallible conversion.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, Source: AsRef<[u8]> + 'a> OctetsFrom<&'a Source> for &'a [u8]

source§

impl<Source> OctetsFrom<Source> for Bytes
where Self: From<Source>,

source§

type Error = Infallible

source§

fn try_octets_from(source: Source) -> Result<Self, Self::Error>

source§

impl<Source> OctetsFrom<Source> for BytesMut
where Self: From<Source>,

source§

type Error = Infallible

source§

fn try_octets_from(source: Source) -> Result<Self, Self::Error>

source§

impl<Source> OctetsFrom<Source> for Vec<u8>
where Self: From<Source>,

source§

type Error = Infallible

source§

fn try_octets_from(source: Source) -> Result<Self, Self::Error>

source§

impl<Source, A> OctetsFrom<Source> for SmallVec<A>
where Source: AsRef<[u8]>, A: Array<Item = u8>,

source§

type Error = Infallible

source§

fn try_octets_from(source: Source) -> Result<Self, Self::Error>

Implementors§

source§

impl<Octs, SrcOcts> OctetsFrom<Str<SrcOcts>> for Str<Octs>
where Octs: OctetsFrom<SrcOcts>,

source§

type Error = <Octs as OctetsFrom<SrcOcts>>::Error

source§

impl<Source: AsRef<[u8]>, const N: usize> OctetsFrom<Source> for Array<N>