Crates.io | dataview |
lib.rs | dataview |
version | 1.0.1 |
source | src |
created_at | 2020-01-11 19:50:53.947213 |
updated_at | 2022-11-04 21:32:56.044058 |
description | Safe transmute between types and byte arrays of the same size. |
homepage | |
repository | https://github.com/CasualX/dataview |
max_upload_size | |
id | 197560 |
size | 37,334 |
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.
This library is available on crates.io.
Documentation can be found on docs.rs.
In your Cargo.toml, put
[dependencies]
dataview = "~1.0"
#[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]);
Licensed under MIT License, see license.txt.
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.