#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

#369 in Parser implementations

Download history 3200/week @ 2023-10-19 3508/week @ 2023-10-26 3276/week @ 2023-11-02 2847/week @ 2023-11-09 3212/week @ 2023-11-16 3298/week @ 2023-11-23 3064/week @ 2023-11-30 3116/week @ 2023-12-07 4671/week @ 2023-12-14 2916/week @ 2023-12-21 2164/week @ 2023-12-28 3673/week @ 2024-01-04 3543/week @ 2024-01-11 3164/week @ 2024-01-18 3762/week @ 2024-01-25 2841/week @ 2024-02-01

14,330 downloads per month
Used in 36 crates (8 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