You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+54
Original file line number
Diff line number
Diff line change
@@ -314,6 +314,60 @@ let my_byte_msb = MyMsbByte::new()
314
314
assert!(my_byte_msb.0==0b1010_0_10_1);
315
315
```
316
316
317
+
## Custom Representation and Endianness
318
+
319
+
The macro supports custom types for the representation of the bitfield struct.
320
+
This can be an endian-defining type like in the following examples (from [`endian-num`]) or any other struct that can be converted to and from the main bitfield type.
321
+
322
+
The representation and its conversion functions can be specified with the following `#[bitfield]` parameters:
323
+
-`repr` specifies the bitfield's representation in memory
324
+
-`from` to specify a conversion function from repr to the bitfield's integer type
325
+
-`into` to specify a conversion function from the bitfield's integer type to repr
326
+
327
+
[`endian-num`]: https://docs.rs/endian-num
328
+
329
+
This example has a little-endian byte order even on big-endian machines:
330
+
331
+
```rust
332
+
usebitfield_struct::bitfield;
333
+
useendian_num::le16;
334
+
335
+
#[bitfield(u16, repr = le16, from = le16::from_ne, into = le16::to_ne)]
This macro automatically creates a suitable `fmt::Debug` and `Default` implementations similar to the ones created for normal structs by `#[derive(Debug, Default)]`.
0 commit comments