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