pub trait ComposeRange: RangeBounds<usize> + Debug {
// Required methods
fn is_valid(&self, len: usize) -> bool;
fn compose(&self, base: Range<usize>) -> Range<usize>;
}Expand description
A range that can check whether it is within the bounds of a slice, and intersect itself with another range.
This trait is implemented for the six Rust range types in core::ops,
making it possible to treat them uniformly in implementations, and in
particular in procedural macros.
Required Methods§
Sourcefn is_valid(&self, len: usize) -> bool
fn is_valid(&self, len: usize) -> bool
Returns true if the range is within the bounds of a slice of given
length
Sourcefn compose(&self, base: Range<usize>) -> Range<usize>
fn compose(&self, base: Range<usize>) -> Range<usize>
Returns a new range that is the composition of base with the range.
The resulting range is guaranteed to be contained in base if self is
valid for base.len().
use value_traits::slices::ComposeRange;
assert_eq!((2..5).compose(10..20), 12..15);
assert_eq!((2..=5).compose(10..20), 12..16);
assert_eq!((..5).compose(10..20), 10..15);
assert_eq!((..=5).compose(10..20), 10..16);
assert_eq!((2..).compose(10..20), 12..20);
assert_eq!((..).compose(10..20), 10..20);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.