Trait SizedEncode

Source
pub trait SizedEncode: Encode {
    const MAX_ENCODED_SIZE: usize;
}
Expand description

Denotes a size-constrained, encodable type.

When using Encode, the size of the resulting encoding cannot always be known beforehand. This trait defines an upper bound for these sizes.

Note that whilst technically having a size limit, alloc::vec::Vec, alloc::string::String, etc. do not implement this trait. The general rule is that the size limit must be a substantial part of a type’s design to constitute implementing this trait.

Also note that – in practice – this trait is not strictly enforceable. Users of this trait should assume that it is mostly properly defined, but still with the possibility of it not being such.

Required Associated Constants§

Source

const MAX_ENCODED_SIZE: usize

The maximum, guaranteed amount of bytes that can result from an encoding.

Implementors of this trait should make sure that no encoding (or decoding) consumes more than the amount specified by this constant.

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 SizedEncode for Infallible

Source§

impl SizedEncode for c_void

Source§

impl SizedEncode for IpAddr

Source§

impl SizedEncode for SocketAddr

Source§

impl SizedEncode for bool

Source§

impl SizedEncode for char

Source§

impl SizedEncode for f16

Available on crate feature f16 only.
Source§

impl SizedEncode for f32

Source§

impl SizedEncode for f64

Source§

impl SizedEncode for f128

Available on crate feature f128 only.
Source§

impl SizedEncode for i8

Source§

impl SizedEncode for i16

Source§

impl SizedEncode for i32

Source§

impl SizedEncode for i64

Source§

impl SizedEncode for i128

Source§

impl SizedEncode for isize

Source§

impl SizedEncode for u8

Source§

impl SizedEncode for u16

Source§

impl SizedEncode for u32

Source§

impl SizedEncode for u64

Source§

impl SizedEncode for u128

Source§

impl SizedEncode for ()

Source§

impl SizedEncode for usize

Source§

const MAX_ENCODED_SIZE: Self = 2usize

Source§

impl SizedEncode for PhantomPinned

Source§

impl SizedEncode for Ipv4Addr

Source§

impl SizedEncode for Ipv6Addr

Source§

impl SizedEncode for SocketAddrV4

Source§

impl SizedEncode for SocketAddrV6

Source§

impl SizedEncode for NonZero<i8>

Source§

impl SizedEncode for NonZero<i16>

Source§

impl SizedEncode for NonZero<i32>

Source§

impl SizedEncode for NonZero<i64>

Source§

impl SizedEncode for NonZero<i128>

Source§

impl SizedEncode for NonZero<isize>

Source§

impl SizedEncode for NonZero<u8>

Source§

impl SizedEncode for NonZero<u16>

Source§

impl SizedEncode for NonZero<u32>

Source§

impl SizedEncode for NonZero<u64>

Source§

impl SizedEncode for NonZero<u128>

Source§

impl SizedEncode for NonZero<usize>

Source§

impl SizedEncode for RangeFull

Source§

impl SizedEncode for AtomicBool

Available on target_has_atomic="8" only.
Source§

impl SizedEncode for AtomicI8

Available on target_has_atomic="8" only.
Source§

impl SizedEncode for AtomicI16

Available on target_has_atomic="16" only.
Source§

impl SizedEncode for AtomicI32

Available on target_has_atomic="32" only.
Source§

impl SizedEncode for AtomicI64

Available on target_has_atomic="64" only.
Source§

impl SizedEncode for AtomicIsize

Available on target_has_atomic="ptr" only.
Source§

impl SizedEncode for AtomicU8

Available on target_has_atomic="8" only.
Source§

impl SizedEncode for AtomicU16

Available on target_has_atomic="16" only.
Source§

impl SizedEncode for AtomicU32

Available on target_has_atomic="32" only.
Source§

impl SizedEncode for AtomicU64

Available on target_has_atomic="64" only.
Source§

impl SizedEncode for AtomicUsize

Available on target_has_atomic="ptr" only.
Source§

impl SizedEncode for Duration

Source§

impl SizedEncode for SystemTime

Available on crate feature std only.
Source§

impl<T, E, Err> SizedEncode for Result<T, E>
where T: Encode<Error = Err> + SizedEncode, E: Encode<Error: Into<Err>> + SizedEncode,

Source§

impl<T: Copy + SizedEncode> SizedEncode for Cell<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized + ToOwned> SizedEncode for Cow<'_, T>

Available on crate feature alloc only.
Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for &T

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for &mut T

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for Box<T>

Available on crate feature alloc only.
Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for Rc<T>

Available on crate feature alloc only.
Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for Arc<T>

Available on crate feature alloc and target_has_atomic="ptr" only.
Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for RefCell<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for Mutex<T>

Available on crate feature std only.
Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode + ?Sized> SizedEncode for RwLock<T>

Available on crate feature std only.
Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for Bound<T>

Source§

impl<T: SizedEncode> SizedEncode for Option<T>

Source§

impl<T: SizedEncode> SizedEncode for (T₁, T₂, …, Tₙ)

Implemented for tuples with up to twelve members.

Source§

impl<T: SizedEncode> SizedEncode for Weak<T>

Available on crate feature alloc only.
Source§

const MAX_ENCODED_SIZE: usize = Option<Rc<T>>::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for Weak<T>

Available on crate feature alloc and target_has_atomic="ptr" only.
Source§

const MAX_ENCODED_SIZE: usize = Option<Arc<T>>::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for LazyCell<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for UnsafeCell<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for Saturating<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for Wrapping<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for Range<T>

Source§

impl<T: SizedEncode> SizedEncode for RangeFrom<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for RangeInclusive<T>

Source§

impl<T: SizedEncode> SizedEncode for RangeTo<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for RangeToInclusive<T>

Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode> SizedEncode for LazyLock<T>

Available on crate feature std only.
Source§

const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE

Source§

impl<T: SizedEncode, const N: usize> SizedEncode for [T; N]

Source§

impl<T: ?Sized> SizedEncode for PhantomData<T>

Implementors§