Skip to content

Commit 76f2c15

Browse files
committed
readme update
1 parent d1fe344 commit 76f2c15

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ provide safe packing, unpacking and runtime debugging formatters with per-field
3535

3636
```toml
3737
[dependencies]
38-
packed_struct = "0.5"
38+
packed_struct = "0.6"
3939
```
4040
## Importing the library with the the most common traits and the derive macros
4141

@@ -190,6 +190,37 @@ fn main() -> Result<(), PackingError> {
190190
}
191191
```
192192

193+
## Nested packed types
194+
195+
```rust
196+
use packed_struct::prelude::*;
197+
#[derive(PackedStruct, Debug, PartialEq)]
198+
#[packed_struct(endian="lsb")]
199+
pub struct Duration {
200+
minutes: u8,
201+
seconds: u8,
202+
}
203+
#[derive(PackedStruct, Debug, PartialEq)]
204+
pub struct Record {
205+
#[packed_field(element_size_bytes="2")]
206+
span: Duration,
207+
events: u8,
208+
}
209+
fn main() -> Result<(), PackingError> {
210+
let example = Record {
211+
span: Duration {
212+
minutes: 10,
213+
seconds: 34,
214+
},
215+
events: 3,
216+
};
217+
let packed = example.pack()?;
218+
let unpacked = Record::unpack(&packed)?;
219+
assert_eq!(example, unpacked);
220+
Ok(())
221+
}
222+
```
223+
193224
## Nested packed types within arrays
194225

195226
```rust

packed_struct/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
//!
3636
//! ```toml
3737
//! [dependencies]
38-
//! packed_struct = "0.5"
38+
//! packed_struct = "0.6"
3939
//! ```
4040
//! ## Importing the library with the the most common traits and the derive macros
4141
//!

0 commit comments

Comments
 (0)