Specifier

Trait Specifier 

Source
pub trait Specifier {
    type Bytes;
    type InOut;

    const BITS: usize;

    // Required methods
    fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>;
    fn from_bytes(
        bytes: Self::Bytes,
    ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>;
}
Expand description

The Specifier trait describes a sequence of bits stored in an integer primitive (the Bytes type) and how to convert them to/from a more convenient higher-level interface type (the InOut type).

For example:

  • The specifier for bool converts between a u8 with a 1 or 0 bit in the lowest bit position and a native bool.
  • The specifier for a unit enum with variants {0, 1, 14} converts between a u16 matching those variants and the enum type.
  • The specifier for a 20-bit struct converts between a u32 and the struct type.

All types used in a #[bitfield] struct must implement this trait, and it should usually only be implemented with #[derive(Specifier)].

Required Associated Constants§

Source

const BITS: usize

The number of bits used by the Specifier.

Required Associated Types§

Source

type Bytes

The storage type. This is typically the smallest integer primitive that can store all possible values of the InOut type.

Source

type InOut

The interface type. This type is used by getters and setters. For integers, this is the same as the Bytes type; for other types with more logical representations, like an enum or struct, this is the enum or struct.

Required Methods§

Source

fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>

Converts an interface type into its storage type.

§Errors

If the input value is out of bounds, an error will be returned. For example, the value b100_u8 cannot be converted with B2 because it is three bits wide.

Source

fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>

Converts a storage type into its interface type.

§Errors

If the given bit pattern is invalid for the interface type, an error will be returned. For example, 3_u8 cannot be converted to an enum which only has variants {0, 1, 2}.

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 Specifier for bool

Source§

const BITS: usize = 1usize

Source§

type Bytes = u8

Source§

type InOut = bool

Source§

fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>

Source§

fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>

Source§

impl Specifier for u8

Source§

const BITS: usize = 8usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>

Source§

fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>

Source§

impl Specifier for u16

Source§

const BITS: usize = 16usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>

Source§

fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>

Source§

impl Specifier for u32

Source§

const BITS: usize = 32usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>

Source§

fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>

Source§

impl Specifier for u64

Source§

const BITS: usize = 64usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>

Source§

fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>

Source§

impl Specifier for u128

Source§

const BITS: usize = 128usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

fn into_bytes(input: Self::InOut) -> Result<Self::Bytes, OutOfBounds>

Source§

fn from_bytes( bytes: Self::Bytes, ) -> Result<Self::InOut, InvalidBitPattern<Self::Bytes>>

Implementors§

Source§

impl Specifier for B1

Source§

const BITS: usize = 1usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B2

Source§

const BITS: usize = 2usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B3

Source§

const BITS: usize = 3usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B4

Source§

const BITS: usize = 4usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B5

Source§

const BITS: usize = 5usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B6

Source§

const BITS: usize = 6usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B7

Source§

const BITS: usize = 7usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B8

Source§

const BITS: usize = 8usize

Source§

type Bytes = u8

Source§

type InOut = u8

Source§

impl Specifier for B9

Source§

const BITS: usize = 9usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B10

Source§

const BITS: usize = 10usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B11

Source§

const BITS: usize = 11usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B12

Source§

const BITS: usize = 12usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B13

Source§

const BITS: usize = 13usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B14

Source§

const BITS: usize = 14usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B15

Source§

const BITS: usize = 15usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B16

Source§

const BITS: usize = 16usize

Source§

type Bytes = u16

Source§

type InOut = u16

Source§

impl Specifier for B17

Source§

const BITS: usize = 17usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B18

Source§

const BITS: usize = 18usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B19

Source§

const BITS: usize = 19usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B20

Source§

const BITS: usize = 20usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B21

Source§

const BITS: usize = 21usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B22

Source§

const BITS: usize = 22usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B23

Source§

const BITS: usize = 23usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B24

Source§

const BITS: usize = 24usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B25

Source§

const BITS: usize = 25usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B26

Source§

const BITS: usize = 26usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B27

Source§

const BITS: usize = 27usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B28

Source§

const BITS: usize = 28usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B29

Source§

const BITS: usize = 29usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B30

Source§

const BITS: usize = 30usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B31

Source§

const BITS: usize = 31usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B32

Source§

const BITS: usize = 32usize

Source§

type Bytes = u32

Source§

type InOut = u32

Source§

impl Specifier for B33

Source§

const BITS: usize = 33usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B34

Source§

const BITS: usize = 34usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B35

Source§

const BITS: usize = 35usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B36

Source§

const BITS: usize = 36usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B37

Source§

const BITS: usize = 37usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B38

Source§

const BITS: usize = 38usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B39

Source§

const BITS: usize = 39usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B40

Source§

const BITS: usize = 40usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B41

Source§

const BITS: usize = 41usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B42

Source§

const BITS: usize = 42usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B43

Source§

const BITS: usize = 43usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B44

Source§

const BITS: usize = 44usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B45

Source§

const BITS: usize = 45usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B46

Source§

const BITS: usize = 46usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B47

Source§

const BITS: usize = 47usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B48

Source§

const BITS: usize = 48usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B49

Source§

const BITS: usize = 49usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B50

Source§

const BITS: usize = 50usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B51

Source§

const BITS: usize = 51usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B52

Source§

const BITS: usize = 52usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B53

Source§

const BITS: usize = 53usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B54

Source§

const BITS: usize = 54usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B55

Source§

const BITS: usize = 55usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B56

Source§

const BITS: usize = 56usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B57

Source§

const BITS: usize = 57usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B58

Source§

const BITS: usize = 58usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B59

Source§

const BITS: usize = 59usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B60

Source§

const BITS: usize = 60usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B61

Source§

const BITS: usize = 61usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B62

Source§

const BITS: usize = 62usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B63

Source§

const BITS: usize = 63usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B64

Source§

const BITS: usize = 64usize

Source§

type Bytes = u64

Source§

type InOut = u64

Source§

impl Specifier for B65

Source§

const BITS: usize = 65usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B66

Source§

const BITS: usize = 66usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B67

Source§

const BITS: usize = 67usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B68

Source§

const BITS: usize = 68usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B69

Source§

const BITS: usize = 69usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B70

Source§

const BITS: usize = 70usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B71

Source§

const BITS: usize = 71usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B72

Source§

const BITS: usize = 72usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B73

Source§

const BITS: usize = 73usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B74

Source§

const BITS: usize = 74usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B75

Source§

const BITS: usize = 75usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B76

Source§

const BITS: usize = 76usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B77

Source§

const BITS: usize = 77usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B78

Source§

const BITS: usize = 78usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B79

Source§

const BITS: usize = 79usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B80

Source§

const BITS: usize = 80usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B81

Source§

const BITS: usize = 81usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B82

Source§

const BITS: usize = 82usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B83

Source§

const BITS: usize = 83usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B84

Source§

const BITS: usize = 84usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B85

Source§

const BITS: usize = 85usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B86

Source§

const BITS: usize = 86usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B87

Source§

const BITS: usize = 87usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B88

Source§

const BITS: usize = 88usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B89

Source§

const BITS: usize = 89usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B90

Source§

const BITS: usize = 90usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B91

Source§

const BITS: usize = 91usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B92

Source§

const BITS: usize = 92usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B93

Source§

const BITS: usize = 93usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B94

Source§

const BITS: usize = 94usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B95

Source§

const BITS: usize = 95usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B96

Source§

const BITS: usize = 96usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B97

Source§

const BITS: usize = 97usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B98

Source§

const BITS: usize = 98usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B99

Source§

const BITS: usize = 99usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B100

Source§

const BITS: usize = 100usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B101

Source§

const BITS: usize = 101usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B102

Source§

const BITS: usize = 102usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B103

Source§

const BITS: usize = 103usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B104

Source§

const BITS: usize = 104usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B105

Source§

const BITS: usize = 105usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B106

Source§

const BITS: usize = 106usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B107

Source§

const BITS: usize = 107usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B108

Source§

const BITS: usize = 108usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B109

Source§

const BITS: usize = 109usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B110

Source§

const BITS: usize = 110usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B111

Source§

const BITS: usize = 111usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B112

Source§

const BITS: usize = 112usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B113

Source§

const BITS: usize = 113usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B114

Source§

const BITS: usize = 114usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B115

Source§

const BITS: usize = 115usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B116

Source§

const BITS: usize = 116usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B117

Source§

const BITS: usize = 117usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B118

Source§

const BITS: usize = 118usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B119

Source§

const BITS: usize = 119usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B120

Source§

const BITS: usize = 120usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B121

Source§

const BITS: usize = 121usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B122

Source§

const BITS: usize = 122usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B123

Source§

const BITS: usize = 123usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B124

Source§

const BITS: usize = 124usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B125

Source§

const BITS: usize = 125usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B126

Source§

const BITS: usize = 126usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B127

Source§

const BITS: usize = 127usize

Source§

type Bytes = u128

Source§

type InOut = u128

Source§

impl Specifier for B128

Source§

const BITS: usize = 128usize

Source§

type Bytes = u128

Source§

type InOut = u128