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
36
37
38
39
40
41
42
43
44
45
46
//! Bit field packing for integer IDs.
//!
//! `nexus-bits` provides ergonomic bit field manipulation for packing
//! multiple values into integers - common in trading systems for
//! instrument IDs, order IDs, and wire protocols.
//!
//! # Example
//!
//! ```
//! use nexus_bits::{BitField, Flag};
//!
//! // Define layout
//! const KIND: BitField<u64> = BitField::<u64>::new(0, 4);
//! const EXCHANGE: BitField<u64> = BitField::<u64>::new(4, 8);
//! const SYMBOL: BitField<u64> = BitField::<u64>::new(12, 20);
//! const IS_TEST: Flag<u64> = Flag::<u64>::new(63);
//!
//! // Pack
//! let mut id: u64 = 0;
//! id = KIND.set(id, 1).unwrap();
//! id = EXCHANGE.set(id, 5).unwrap();
//! id = SYMBOL.set(id, 12345).unwrap();
//! id = IS_TEST.set(id);
//!
//! // Unpack
//! assert_eq!(KIND.get(id), 1);
//! assert_eq!(EXCHANGE.get(id), 5);
//! assert_eq!(SYMBOL.get(id), 12345);
//! assert!(IS_TEST.is_set(id));
//! ```
pub use ;
pub use BitField;
pub use Flag;
pub use IntEnum;
pub use ;