#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

#1265 in Parser implementations

Download history 2735/week @ 2024-08-02 2876/week @ 2024-08-09 2839/week @ 2024-08-16 2731/week @ 2024-08-23 2658/week @ 2024-08-30 2686/week @ 2024-09-06 2684/week @ 2024-09-13 3120/week @ 2024-09-20 2879/week @ 2024-09-27 2701/week @ 2024-10-04 2551/week @ 2024-10-11 3322/week @ 2024-10-18 3022/week @ 2024-10-25 3073/week @ 2024-11-01 3053/week @ 2024-11-08 4315/week @ 2024-11-15

14,025 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