range_split/take_range.rs
1/// Methods for splitting out part of a collection with a given range.
2pub trait TakeRange<R> {
3 /// The value returned by the `take_range` method, representing
4 /// the extracted part of the collection.
5 type Output;
6
7 /// Splits off and returns part of the collection designated by
8 /// the given range. The remaining part is left in `self` with indices
9 /// adjusted after the removal.
10 ///
11 /// The range parameter typically has one of the standard range types
12 /// constructed with [range expression][range-expr] syntax.
13 ///
14 /// [range-expr]: https://doc.rust-lang.org/reference/expressions/range-expr.html
15 ///
16 /// # Panics
17 ///
18 /// The implementation can panic if the range is not valid for the
19 /// operation.
20 fn take_range(&mut self, range: R) -> Self::Output;
21
22 /// Removes items from the the collection as designated by
23 /// the given range. The remaining part is left in `self` with indices
24 /// adjusted after the removal.
25 ///
26 /// The range parameter typically has one of the standard range types
27 /// constructed with [range expression][range-expr] syntax.
28 ///
29 /// The default implementation of this method calls `take_range` and
30 /// drops the returned value. Implementors of the trait should consider
31 /// a more efficient implementation, avoiding construction of an
32 /// intermediate container.
33 ///
34 /// [range-expr]: https://doc.rust-lang.org/reference/expressions/range-expr.html
35 ///
36 /// # Panics
37 ///
38 /// The implementation can panic if the range is not valid for the
39 /// operation.
40 fn remove_range(&mut self, range: R) {
41 self.take_range(range);
42 }
43}