1 
2 use std::ops::{
3     RangeFull,
4     RangeFrom,
5     RangeTo,
6     Range,
7 };
8 
9 /// `RangeArgument` is implemented by Rust's built-in range types, produced
10 /// by range syntax like `..`, `a..`, `..b` or `c..d`.
11 ///
12 /// Note: This is arrayvec's provisional trait, waiting for stable Rust to
13 /// provide an equivalent.
14 pub trait RangeArgument {
15     #[inline]
16     /// Start index (inclusive)
start(&self) -> Option<usize>17     fn start(&self) -> Option<usize> { None }
18     #[inline]
19     /// End index (exclusive)
end(&self) -> Option<usize>20     fn end(&self) -> Option<usize> { None }
21 }
22 
23 
24 impl RangeArgument for RangeFull {}
25 
26 impl RangeArgument for RangeFrom<usize> {
27     #[inline]
start(&self) -> Option<usize>28     fn start(&self) -> Option<usize> { Some(self.start) }
29 }
30 
31 impl RangeArgument for RangeTo<usize> {
32     #[inline]
end(&self) -> Option<usize>33     fn end(&self) -> Option<usize> { Some(self.end) }
34 }
35 
36 impl RangeArgument for Range<usize> {
37     #[inline]
start(&self) -> Option<usize>38     fn start(&self) -> Option<usize> { Some(self.start) }
39     #[inline]
end(&self) -> Option<usize>40     fn end(&self) -> Option<usize> { Some(self.end) }
41 }
42 
43