https://github.com/rukai/fancy_slice
Wraps an `&[u8]` slice to provide a kitchen sink worth of tools.
https://github.com/rukai/fancy_slice
Last synced: 3 months ago
JSON representation
Wraps an `&[u8]` slice to provide a kitchen sink worth of tools.
- Host: GitHub
- URL: https://github.com/rukai/fancy_slice
- Owner: rukai
- License: mit
- Created: 2019-04-11T03:07:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-25T12:07:56.000Z (about 2 years ago)
- Last Synced: 2025-03-14T20:20:04.126Z (3 months ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# Fancy Slice
[](https://travis-ci.com/rukai/fancy_slice) [](https://deps.rs/repo/github/rukai/fancy_slice) [](https://crates.io/crates/fancy_slice) [](https://docs.rs/fancy_slice)Wraps an `&[u8]` slice to provide a kitchen sink worth of tools.
Useful for writing a binary format parser that needs to be reverse engineered as you go.Mostly untested, so gauranteed to have off-by-one errors. :P
Enable the `debug` feature to add extra functions.
You should only enable the debug feature during development as it comes with a performance hit due to storing extra data in FancySlice.```rust
use fancy_slice::FancySlice;fn main() {
let data = vec!(4, 1, 3);
let fancy_slice = FancySlice::new(&data);
assert_eq!(fancy_slice.u8(0), 4);
assert_eq!(fancy_slice.u8(1), 1);
assert_eq!(fancy_slice.u8(2), 3);
assert_eq!(fancy_slice.u16_be(0), 0x0401);
assert_eq!(fancy_slice.u16_be(1), 0x0103);let inner_fancy_slice = fancy_slice.relative_fancy_slice(1..);
assert_eq!(inner_fancy_slice.u8(0), 1);
assert_eq!(inner_fancy_slice.u8(1), 3);
assert_eq!(inner_fancy_slice.u16_be(0), 0x0103);
}
```