#binary #data #view #pod

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

#161 in Parser implementations

Download history 3010/week @ 2023-02-17 2772/week @ 2023-02-24 3246/week @ 2023-03-03 3449/week @ 2023-03-10 3634/week @ 2023-03-17 3437/week @ 2023-03-24 3426/week @ 2023-03-31 2114/week @ 2023-04-07 2972/week @ 2023-04-14 3002/week @ 2023-04-21 3127/week @ 2023-04-28 2983/week @ 2023-05-05 2802/week @ 2023-05-12 2703/week @ 2023-05-19 2365/week @ 2023-05-26 2846/week @ 2023-06-02

11,317 downloads per month
Used in 31 crates (7 directly)

MIT license

34KB
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