Trait BitEncode

Source
pub trait BitEncode<Ctx = (), Tag = ()> {
    // Required method
    fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
       where W: BitWrite,
             E: Endianness;

    // Provided method
    fn encode_bytes_ctx<E>(
        &self,
        byte_order: E,
        ctx: &mut Ctx,
        tag: Tag,
    ) -> Result<Vec<u8>>
       where E: Endianness { ... }
}
Expand description

A trait for bit-level encoding.

Required Methods§

Source

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Writes a value to a stream.

Provided Methods§

Source

fn encode_bytes_ctx<E>( &self, byte_order: E, ctx: &mut Ctx, tag: Tag, ) -> Result<Vec<u8>>
where E: Endianness,

Gets the raw bytes of this type with provided context and tag.

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<'a, Ctx, Tag, T> BitEncode<Ctx, Tag> for Cow<'a, T>
where T: BitEncode<Ctx, Tag> + ToOwned + ?Sized + 'a,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for bool

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for f32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for f64

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for i8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for i16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for i32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for i64

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for i128

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for isize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for str

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for u8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for u16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for u32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for u64

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for u128

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for ()

Source§

fn encode<W, E>(&self, _: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for usize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for CString

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for CStr

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for PhantomPinned

Source§

fn encode<W, E>(&self, _: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for Ipv4Addr

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for Ipv6Addr

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroI8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroI16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroI32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroI64

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroI128

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroIsize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroU8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroU16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroU32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroU64

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroU128

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx> for NonZeroUsize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx> BitEncode<Ctx, Untagged> for String

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, K, V> BitEncode<Ctx, Untagged> for BTreeMap<K, V>
where K: BitEncode<Ctx> + Ord, V: BitEncode<Ctx>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, K, V, H> BitEncode<Ctx, Untagged> for HashMap<K, V, H>
where K: BitEncode<Ctx> + Eq + Hash, V: BitEncode<Ctx>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx> for [T]
where T: BitEncode<Ctx>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx> for PhantomData<T>

Source§

fn encode<W, E>(&self, _: &mut W, _: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx, Untagged> for Option<T>
where T: BitEncode<Ctx>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx, Untagged> for BinaryHeap<T>
where T: BitEncode<Ctx> + Ord,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx, Untagged> for BTreeSet<T>
where T: BitEncode<Ctx> + Ord,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx, Untagged> for LinkedList<T>
where T: BitEncode<Ctx>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx, Untagged> for VecDeque<T>
where T: BitEncode<Ctx>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T> BitEncode<Ctx, Untagged> for Vec<T>
where T: BitEncode<Ctx>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T, H> BitEncode<Ctx, Untagged> for HashSet<T, H>
where T: BitEncode<Ctx> + Hash + Eq,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, _: Untagged) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, T, const N: usize> BitEncode<Ctx> for [T; N]
where T: BitEncode<Ctx> + Sized,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, (): ()) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for &T
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for &mut T
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for (T₁, T₂, …, Tₙ)
where T: BitEncode<Ctx, Tag>,

This trait is implemented for tuples with up to 16 items.

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for Box<T>
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for Rc<T>
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for Arc<T>
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for Cell<T>
where T: BitEncode<Ctx, Tag> + Copy,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for RefCell<T>
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for Saturating<T>
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for Wrapping<T>
where T: BitEncode<Ctx, Tag>,

Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for Mutex<T>
where T: BitEncode<Ctx, Tag>,

Available on crate feature std only.
Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, Tag, T> BitEncode<Ctx, Tag> for RwLock<T>
where T: BitEncode<Ctx, Tag>,

Available on crate feature std only.
Source§

fn encode<W, E>(&self, write: &mut W, ctx: &mut Ctx, tag: Tag) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for bool

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for i8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for i16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for i32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for i64

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for isize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for u8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for u16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for u32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for u64

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for usize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroI8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroI16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroI32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroIsize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroU8

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroU16

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroU32

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Source§

impl<Ctx, const C: u32> BitEncode<Ctx, Bits<C>> for NonZeroUsize

Source§

fn encode<W, E>(&self, write: &mut W, _: &mut Ctx, _: Bits<C>) -> Result<()>
where W: BitWrite, E: Endianness,

Implementors§