1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use core::any::Any;

use crate::{BitRead, BitWrite, ByteOrder, Error};

/// A trait for variable-width bit-level co/dec.
///
/// **WARNING**: This trait can and often will ignore the endianness.
pub trait BitField: Sized {
    fn read(
        read: &mut dyn BitRead,
        byte_order: ByteOrder,
        ctx: &mut dyn Any,
        bits: u32,
    ) -> Result<Self, Error>;

    fn write(
        &self,
        write: &mut dyn BitWrite,
        byte_order: ByteOrder,
        ctx: &mut dyn Any,
        bits: u32,
    ) -> Result<(), Error>;
}

/// ```compile_fail
/// #[derive(bin_proto::Protocol)]
/// #[protocol(discriminant_type = "u8")]
/// #[protocol(bits = 1)]
/// enum WontFit {
///     Variant = 2,
/// }
/// ```
#[cfg(all(feature = "derive", doctest))]
#[allow(unused)]
fn compile_fail_if_discriminant_wont_fit() {}