Read

Trait Read 

Source
pub trait Read: Sized {
    type Cfg: Clone + Send + Sync + 'static;

    // Required method
    fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>;
}
Expand description

Trait for types that can be read (decoded) from a byte buffer.

Required Associated Types§

Source

type Cfg: Clone + Send + Sync + 'static

The Cfg type parameter allows passing configuration during the read process. This is crucial for safely decoding untrusted data, for example, by providing size limits for collections or strings.

Use Cfg = () if no configuration is needed for a specific type.

Required Methods§

Source

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Reads a value from the buffer using the provided configuration cfg.

Implementations should consume the exact number of bytes required from buf to reconstruct the value.

Returns Error if decoding fails due to invalid data, insufficient bytes in the buffer, or violation of constraints imposed by the cfg.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Read for SocketAddr

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for bool

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for f32

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for f64

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for i8

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for i16

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for i32

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for i64

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for i128

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for u8

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for u16

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for u32

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for u64

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for u128

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for usize

Source§

type Cfg = RangeCfg

Source§

fn read_cfg(buf: &mut impl Buf, range: &Self::Cfg) -> Result<Self, Error>

Source§

impl Read for Ipv4Addr

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for Ipv6Addr

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for SocketAddrV4

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for SocketAddrV6

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Source§

impl Read for Bytes

Source§

type Cfg = RangeCfg

Source§

fn read_cfg(buf: &mut impl Buf, range: &Self::Cfg) -> Result<Self, Error>

Source§

impl<K: Read + Clone + Ord + Eq> Read for BTreeSet<K>

Source§

type Cfg = (RangeCfg, <K as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, (range, cfg): &Self::Cfg) -> Result<Self, Error>

Source§

impl<K: Read + Clone + Ord + Eq, V: Read + Clone> Read for BTreeMap<K, V>

Source§

type Cfg = (RangeCfg, (<K as Read>::Cfg, <V as Read>::Cfg))

Source§

fn read_cfg( buf: &mut impl Buf, (range, (k_cfg, v_cfg)): &Self::Cfg, ) -> Result<Self, Error>

Source§

impl<K: Read + Clone + Ord + Hash + Eq> Read for HashSet<K>

Source§

type Cfg = (RangeCfg, <K as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, (range, cfg): &Self::Cfg) -> Result<Self, Error>

Source§

impl<K: Read + Clone + Ord + Hash + Eq, V: Read + Clone> Read for HashMap<K, V>

Source§

type Cfg = (RangeCfg, (<K as Read>::Cfg, <V as Read>::Cfg))

Source§

fn read_cfg( buf: &mut impl Buf, (range, (k_cfg, v_cfg)): &Self::Cfg, ) -> Result<Self, Error>

Source§

impl<T0: Read> Read for (T0,)

Source§

type Cfg = (<T0 as Read>::Cfg,)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read> Read for (T0, T1)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read> Read for (T0, T1, T2)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read> Read for (T0, T1, T2, T3)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read> Read for (T0, T1, T2, T3, T4)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read, T5: Read> Read for (T0, T1, T2, T3, T4, T5)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg, <T5 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read, T5: Read, T6: Read> Read for (T0, T1, T2, T3, T4, T5, T6)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg, <T5 as Read>::Cfg, <T6 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read, T5: Read, T6: Read, T7: Read> Read for (T0, T1, T2, T3, T4, T5, T6, T7)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg, <T5 as Read>::Cfg, <T6 as Read>::Cfg, <T7 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read, T5: Read, T6: Read, T7: Read, T8: Read> Read for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg, <T5 as Read>::Cfg, <T6 as Read>::Cfg, <T7 as Read>::Cfg, <T8 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read, T5: Read, T6: Read, T7: Read, T8: Read, T9: Read> Read for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg, <T5 as Read>::Cfg, <T6 as Read>::Cfg, <T7 as Read>::Cfg, <T8 as Read>::Cfg, <T9 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read, T5: Read, T6: Read, T7: Read, T8: Read, T9: Read, T10: Read> Read for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg, <T5 as Read>::Cfg, <T6 as Read>::Cfg, <T7 as Read>::Cfg, <T8 as Read>::Cfg, <T9 as Read>::Cfg, <T10 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T0: Read, T1: Read, T2: Read, T3: Read, T4: Read, T5: Read, T6: Read, T7: Read, T8: Read, T9: Read, T10: Read, T11: Read> Read for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

type Cfg = (<T0 as Read>::Cfg, <T1 as Read>::Cfg, <T2 as Read>::Cfg, <T3 as Read>::Cfg, <T4 as Read>::Cfg, <T5 as Read>::Cfg, <T6 as Read>::Cfg, <T7 as Read>::Cfg, <T8 as Read>::Cfg, <T9 as Read>::Cfg, <T10 as Read>::Cfg, <T11 as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T: Read> Read for Option<T>

Source§

type Cfg = <T as Read>::Cfg

Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Source§

impl<T: Read> Read for Vec<T>

Source§

type Cfg = (RangeCfg, <T as Read>::Cfg)

Source§

fn read_cfg(buf: &mut impl Buf, (range, cfg): &Self::Cfg) -> Result<Self, Error>

Source§

impl<const N: usize> Read for [u8; N]

Source§

type Cfg = ()

Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Implementors§

Source§

impl<S: SPrim> Read for SInt<S>

Source§

impl<U: UPrim> Read for UInt<U>