6 releases (3 stable)
| new 1.0.2 | Jan 16, 2026 |
|---|---|
| 1.0.1 | Nov 4, 2022 |
| 1.0.0 | Jul 5, 2022 |
| 0.1.2 | Apr 27, 2021 |
| 0.1.1 | Jan 19, 2020 |
#156 in Parser implementations
18,861 downloads per month
Used in 66 crates
(13 directly)
34KB
703 lines
DataView
The Pod trait marks types whose values can be safely transmuted between byte arrays of the same size.
The DataView type defines read and write data APIs to an underlying byte buffer.
Library
This library is available on crates.io.
Documentation can be found on docs.rs.
In your Cargo.toml, put
[dependencies]
dataview = "~1.0"
Examples
#[derive(dataview::Pod)]
#[repr(C)]
struct MyType {
field: i32,
}
// Construct a zero initialized instance
let mut inst: MyType = dataview::zeroed();
assert_eq!(inst.field, 0);
// Use DataView to access the instance
let view = dataview::DataView::from_mut(&mut inst);
view.write(2, &255_u8);
// Create a byte view over the instance
assert_eq!(dataview::bytes(&inst), &[0, 0, 255, 0]);
License
Licensed under MIT License, see license.txt.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.