ntex_bytes/
lib.rs

1//! Provides abstractions for working with bytes.
2//!
3//! This is fork of [bytes crate](https://github.com/tokio-rs/bytes)
4//!
5//! The `ntex-bytes` crate provides an efficient byte buffer structure
6//! ([`Bytes`](struct.Bytes.html)) and traits for working with buffer
7//! implementations ([`Buf`], [`BufMut`]).
8//!
9//! [`Buf`]: trait.Buf.html
10//! [`BufMut`]: trait.BufMut.html
11//!
12//! # `Bytes`
13//!
14//! `Bytes` is an efficient container for storing and operating on contiguous
15//! slices of memory. It is intended for use primarily in networking code, but
16//! could have applications elsewhere as well.
17//!
18//! `Bytes` values facilitate zero-copy network programming by allowing multiple
19//! `Bytes` objects to point to the same underlying memory. This is managed by
20//! using a reference count to track when the memory is no longer needed and can
21//! be freed.
22//!
23//! A `Bytes` handle can be created directly from an existing byte store (such as `&[u8]`
24//! or `Vec<u8>`), but usually a `BytesMut` is used first and written to. For
25//! example:
26//!
27//! ```rust
28//! use ntex_bytes::{BytesMut, BufMut};
29//!
30//! let mut buf = BytesMut::with_capacity(1024);
31//! buf.put(&b"hello world"[..]);
32//! buf.put_u16(1234);
33//!
34//! let a = buf.split();
35//! assert_eq!(a, b"hello world\x04\xD2"[..]);
36//!
37//! buf.put(&b"goodbye world"[..]);
38//!
39//! let b = buf.split();
40//! assert_eq!(b, b"goodbye world"[..]);
41//!
42//! assert_eq!(buf.capacity(), 998);
43//! ```
44//!
45//! In the above example, only a single buffer of 1024 is allocated. The handles
46//! `a` and `b` will share the underlying buffer and maintain indices tracking
47//! the view into the buffer represented by the handle.
48//!
49//! See the [struct docs] for more details.
50//!
51//! [struct docs]: struct.Bytes.html
52
53#![deny(warnings, missing_debug_implementations, rust_2018_idioms)]
54#![doc(html_root_url = "https://docs.rs/ntex-bytes/")]
55
56pub mod buf;
57pub use crate::buf::{Buf, BufMut};
58
59mod bytes;
60mod debug;
61mod hex;
62mod pool;
63mod serde;
64mod string;
65
66pub use crate::bytes::{Bytes, BytesMut, BytesVec};
67pub use crate::string::ByteString;
68
69#[doc(hidden)]
70pub use crate::pool::{Pool, PoolId, PoolRef};