https://github.com/zakarumych/safe-bytes
Simple crate to allow reading bytes representation of structures soundly.
https://github.com/zakarumych/safe-bytes
Last synced: about 2 months ago
JSON representation
Simple crate to allow reading bytes representation of structures soundly.
- Host: GitHub
- URL: https://github.com/zakarumych/safe-bytes
- Owner: zakarumych
- License: other
- Created: 2020-06-18T17:12:13.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T18:05:53.000Z (almost 5 years ago)
- Last Synced: 2024-10-31T11:40:26.077Z (8 months ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# safe-bytes
This crate allows reading bytes representation of structs
even in presence of padding bytes.[](https://crates.io/crates/safe-bytes)
[](https://docs.rs/safe-bytes)
[](LICENSE-MIT)
[](LICENSE-APACHE)Simply derive [`SafeBytes`] for structures
where all field types are [`SafeBytes`] implementations.
And [`SafeBytes::safe_bytes`] would initialize all padding bytes
before returning `&[u8]`.
All primitives implement [`SafeBytes`] as there is no padding bytes.
Additionally some std types implement [`SafeBytes`].Note that in order to initialize padding bytes
[`SafeBytes::safe_bytes`] takes mutable reference `&mut self`.
And returns shareable reference `&[u8]` because not all
bitpatterns may be allowed for the type.[`SafeBytes`]: https://docs.rs/safe-bytes/0.1.0/safe_bytes/trait.SafeBytes.html
[`SafeBytes::safe_bytes`]: https://docs.rs/safe-bytes/0.1.0/safe_bytes/trait.SafeBytes.html#tymethod.safe_bytes## License
This repository is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.
### Contribution Licensing
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.