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 `BytesMut` store
24//! is used first and written to. For example:
25//!
26//! ```rust
27//! use ntex_bytes::{BytesMut, BufMut};
28//!
29//! let mut buf = BytesMut::with_capacity(1024);
30//! buf.put(&b"hello world"[..]);
31//! buf.put_u16(1234);
32//!
33//! let a = buf.take();
34//! assert_eq!(a, b"hello world\x04\xD2"[..]);
35//!
36//! buf.put(&b"goodbye world"[..]);
37//!
38//! let b = buf.take();
39//! assert_eq!(b, b"goodbye world"[..]);
40//!
41//! assert_eq!(buf.capacity(), 998);
42//! ```
43//!
44//! In the above example, only a single buffer of 1024 is allocated. The handles
45//! `a` and `b` will share the underlying buffer and maintain indices tracking
46//! the view into the buffer represented by the handle.
47//!
48//! See the [struct docs] for more details.
49//!
50//! [struct docs]: struct.Bytes.html
51
52#![deny(warnings, missing_debug_implementations, rust_2018_idioms)]
53#![doc(html_root_url = "https://docs.rs/ntex-bytes/")]
54#![allow(unsafe_op_in_unsafe_fn)]
55
56extern crate alloc;
57
58pub mod buf;
59pub use crate::buf::{Buf, BufMut};
60
61mod bvec;
62mod bytes;
63mod debug;
64mod hex;
65mod serde;
66mod storage;
67mod string;
68
69pub use crate::bvec::BytesMut;
70pub use crate::bytes::Bytes;
71pub use crate::string::ByteString;
72
73#[doc(hidden)]
74#[deprecated]
75pub type BytesVec = BytesMut;
76
77#[doc(hidden)]
78pub mod info {
79    #[derive(Copy, Clone, Debug, Eq, PartialEq)]
80    pub struct Info {
81        pub id: usize,
82        pub refs: usize,
83        pub kind: Kind,
84        pub capacity: usize,
85    }
86
87    #[derive(Copy, Clone, Debug, Eq, PartialEq)]
88    pub enum Kind {
89        Arc,
90        Inline,
91        Static,
92        Vec,
93    }
94}