#buffer #collection

range-split

Utilities for splitting sequences with range parameters

7 unstable releases (3 breaking)

0.4.0 Jan 28, 2021
0.3.0 Oct 28, 2020
0.2.0 Dec 1, 2019
0.2.0-beta.2 Nov 28, 2019
0.1.0-beta.1 Jun 16, 2019

#1985 in Data structures

29 downloads per month
Used in strchunk

MIT license

14KB
256 lines

Splitting Sequences with Range Syntax

This library crate provides a trait and support utilities adding convenience methods for splitting sequences accordingly to a given range.

The primary use case for the TakeRange trait are data container libraries such as bytes, where representations of data buffers can be efficiently split into smaller parts, but the inherent methods for doing this tend to be not very mnemonic. Implementations of the trait parameterized with different range types provide convenient polymorphism with the range syntax.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in range-split by you, shall be licensed as MIT, without any additional terms or conditions.


lib.rs:

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.

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, ", ");

is equivalent to

#
let mut buf = Bytes::from("Hello, world");
let p = buf.split_to(5);
buf.truncate(2);

Implementations of TakeRange are provided for Bytes and BytesMut from the crate bytes if the bytes compile-time feature is enabled.

Dependencies

~175KB