mco_redis/bytes/
mod.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 mco_redis::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
52pub mod buf;
53pub use self::buf::{Buf, BufMut};
54
55mod bytes;
56mod debug;
57mod hex;
58mod pool;
59mod serde;
60mod string;
61
62pub use self::bytes::{Bytes, BytesMut, BytesVec};
63pub use self::string::ByteString;
64
65#[doc(hidden)]
66pub use self::pool::{Pool, PoolId, PoolRef};