Skip to content

Commit 7d39243

Browse files
Merge pull request #8 from triblespace/codex/add-quick-start-section-to-readme.md
Add Quick Start to README
2 parents 7fedfa8 + 44c5b35 commit 7d39243

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ and is implemented for a variety of sources already,
1313
including other byte handling crates `Bytes`, mmap-ed files,
1414
`String`s and `Zerocopy` types.
1515

16+
## Quick Start
17+
18+
```rust
19+
use anybytes::Bytes;
20+
21+
fn main() {
22+
// create `Bytes` from a vector
23+
let bytes = Bytes::from(vec![1u8, 2, 3, 4]);
24+
25+
// take a zero-copy slice
26+
let slice = bytes.slice(1..3);
27+
28+
// convert it to a typed View
29+
let view = slice.view::<[u8]>().unwrap();
30+
assert_eq!(&*view, &[2, 3]);
31+
}
32+
```
33+
1634
## Features
1735

1836
By default the crate enables the `mmap` and `zerocopy` features.

0 commit comments

Comments
 (0)