range_split/
lib.rs

1//! Utilities for splitting sequences with range parameters.
2//!
3//! The `TakeRange` trait provides polymorphic, easily memorizable methods
4//! for splitting indexed sequences with a parameter given in range syntax.
5//!
6//! ```
7//! # #[cfg(features = "bytes")]
8//! # fn main() {
9//! # use bytes::Bytes;
10//! use range_split::TakeRange;
11//!
12//! let mut buf = Bytes::from("Hello, world");
13//! let p = buf.take_range(..5);
14//! buf.remove_range(2..);
15//! assert_eq!(p, "Hello");
16//! assert_eq!(buf, ", ");
17//! # }
18//! # #[cfg(not(features = "bytes"))]
19//! # fn main() {}
20//! ```
21//!
22//! is equivalent to
23//!
24//! ```
25//! # #[cfg(features = "bytes")]
26//! # fn main() {
27//! # use bytes::Bytes;
28//! #
29//! let mut buf = Bytes::from("Hello, world");
30//! let p = buf.split_to(5);
31//! buf.truncate(2);
32//! # }
33//! # #[cfg(not(features = "bytes"))]
34//! # fn main() {}
35//! ```
36//!
37//! Implementations of `TakeRange` are provided for `Bytes` and `BytesMut`
38//! from the crate `bytes` if the `bytes` compile-time feature is enabled.
39
40#![warn(rust_2018_idioms)]
41#![warn(missing_docs)]
42#![warn(clippy::all)]
43
44#![no_std]
45
46pub mod mem;
47pub mod str;
48mod take_range;
49
50#[macro_use]
51#[cfg_attr(not(feature = "bytes"), allow(unused_macros))]
52mod impl_macro;
53
54#[cfg(feature = "bytes")]
55mod bytes;
56
57pub use take_range::TakeRange;