#byte-array #byte-buffer #binary-data #pod #binary #view #read-write

dataview

Safe transmute between types and byte arrays of the same size

5 releases (2 stable)

1.0.1 Nov 4, 2022
1.0.0 Jul 5, 2022
0.1.2 Apr 27, 2021
0.1.1 Jan 19, 2020
0.1.0 Jan 11, 2020

#1126 in Parser implementations

Download history 3481/week @ 2024-07-22 2954/week @ 2024-07-29 2815/week @ 2024-08-05 2981/week @ 2024-08-12 2966/week @ 2024-08-19 2723/week @ 2024-08-26 2547/week @ 2024-09-02 2676/week @ 2024-09-09 2580/week @ 2024-09-16 3304/week @ 2024-09-23 2779/week @ 2024-09-30 2591/week @ 2024-10-07 2612/week @ 2024-10-14 3366/week @ 2024-10-21 3022/week @ 2024-10-28 2996/week @ 2024-11-04

12,128 downloads per month
Used in 39 crates (9 directly)

MIT license

35KB
698 lines

DataView

MIT License crates.io docs.rs Build status

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.

Dependencies