pub struct Range<I> {
pub(crate) begin: I,
pub(crate) length: I,
}
Expand description
A range of indices
Fields§
§begin: I
§length: I
Implementations§
source§impl<I: RangeIndex> Range<I>
impl<I: RangeIndex> Range<I>
sourcepub fn new(begin: I, length: I) -> Range<I>
pub fn new(begin: I, length: I) -> Range<I>
Create a new range from beginning and length offsets. This could be
denoted as [begin, begin + length)
.
ⓘ
|-- begin ->|-- length ->|
| | |
<- o - - - - - +============+ - - - ->
pub fn empty() -> Range<I>
sourcepub fn begin(&self) -> I
pub fn begin(&self) -> I
The index offset to the beginning of the range.
ⓘ
|-- begin ->|
| |
<- o - - - - - +============+ - - - ->
sourcepub fn length(&self) -> I
pub fn length(&self) -> I
The index offset from the beginning to the end of the range.
ⓘ
|-- length ->|
| |
<- o - - - - - +============+ - - - ->
sourcepub fn end(&self) -> I
pub fn end(&self) -> I
The index offset to the end of the range.
ⓘ
|--------- end --------->|
| |
<- o - - - - - +============+ - - - ->
sourcepub fn contains(&self, i: I) -> bool
pub fn contains(&self, i: I) -> bool
true
if the index is between the beginning and the end of the range.
ⓘ
false true false
| | |
<- o - - + - - +=====+======+ - + - ->
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true
if the offset from the beginning to the end of the range is zero.
sourcepub fn shift_by(&mut self, delta: I)
pub fn shift_by(&mut self, delta: I)
Shift the entire range by the supplied index delta.
ⓘ
|-- delta ->|
| |
<- o - +============+ - - - - - | - - - ->
|
<- o - - - - - - - +============+ - - - ->
sourcepub fn extend_by(&mut self, delta: I)
pub fn extend_by(&mut self, delta: I)
Extend the end of the range by the supplied index delta.
ⓘ
|-- delta ->|
| |
<- o - - - - - +====+ - - - - - | - - - ->
|
<- o - - - - - +================+ - - - ->
sourcepub fn extend_to(&mut self, target: I)
pub fn extend_to(&mut self, target: I)
Move the end of the range to the target index.
ⓘ
target
|
<- o - - - - - +====+ - - - - - | - - - ->
|
<- o - - - - - +================+ - - - ->
sourcepub fn adjust_by(&mut self, begin_delta: I, length_delta: I)
pub fn adjust_by(&mut self, begin_delta: I, length_delta: I)
Adjust the beginning offset and the length by the supplied deltas.
pub fn intersect(&self, other: &Range<I>) -> Range<I>
source§impl<I: RangeIndex> Range<I>
impl<I: RangeIndex> Range<I>
Methods for Range
s with indices based on integer values
sourcepub fn each_index(&self) -> EachIndex<I> ⓘ
pub fn each_index(&self) -> EachIndex<I> ⓘ
Returns an iterater that increments over [begin, end)
.
Trait Implementations§
source§impl<I: RangeIndex> Debug for Range<I>
impl<I: RangeIndex> Debug for Range<I>
source§impl<'de, I> Deserialize<'de> for Range<I>where
I: Deserialize<'de>,
impl<'de, I> Deserialize<'de> for Range<I>where
I: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<I> MallocSizeOf for Range<I>where
I: MallocSizeOf,
impl<I> MallocSizeOf for Range<I>where
I: MallocSizeOf,
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Measure the heap usage of all descendant heap-allocated structures, but
not the space taken up by the value itself.
impl<I: Copy> Copy for Range<I>
Auto Trait Implementations§
impl<I> Freeze for Range<I>where
I: Freeze,
impl<I> RefUnwindSafe for Range<I>where
I: RefUnwindSafe,
impl<I> Send for Range<I>where
I: Send,
impl<I> Sync for Range<I>where
I: Sync,
impl<I> Unpin for Range<I>where
I: Unpin,
impl<I> UnwindSafe for Range<I>where
I: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more