[−][src]Struct str_index::StrRange
A range of a string, represented as a half-open range of StrIndex.
Construct a StrRange by using from conversion from std::ops::Range/RangeTo.
The range is always guaranteed increasing; conversion panics if end < start.
Examples
let zero = StrIndex::from(0); let start = StrIndex::from(10); let end = StrIndex::from(20); assert_eq!( format!("{:?}", StrRange::from(start..end)), format!("{:?}", start..end), ); assert_eq!( format!("{:?}", StrRange::from(..end)), format!("{:?}", zero..end), );
let this_panics = StrRange::from(end..start);
Methods
impl StrRange[src]
pub fn start(self) -> StrIndex[src]
The (inclusive) start index of this range.
pub fn end(self) -> StrIndex[src]
The (exclusive) end index of this range.
pub fn len(self) -> StrIndex[src]
The length of this range.
pub fn is_empty(self) -> bool[src]
Is this range a unit range? That is, does this range have equivalent start and end points?
pub fn with_start(self, start: StrIndex) -> StrRange[src]
A range with an adjusted end.
Panics
Panics if self.end() < start.
Example
let range = StrRange::from(5.into()..10.into()); let point = StrIndex::from(0); assert_eq!( range.with_start(point), point.range_to(range.end()), );
pub fn with_end(self, end: StrIndex) -> StrRange[src]
A range with an adjusted end.
Panics
Panics if end < self.start().
Example
let range = StrRange::from(0.into()..5.into()); let point = StrIndex::from(10); assert_eq!( range.with_end(point), range.start().range_to(point), );
pub fn is_disjoint(self, other: StrRange) -> bool[src]
Are these ranges disjoint?
Ranges that touch end to start are disjoint, as no byte is in both ranges.
Examples
let left = StrRange::from(0.into()..20.into()); let right = StrRange::from(10.into()..30.into()); assert!(!left.is_disjoint(right)); assert!(!right.is_disjoint(left)); let left = StrRange::from(0.into()..10.into()); let right = StrRange::from(10.into()..20.into()); assert!(left.is_disjoint(right)); assert!(right.is_disjoint(left)); let empty = StrRange::from(10.into()..10.into()); assert!(empty.is_disjoint(empty));
pub fn intersection(self, other: Self) -> Option<Self>[src]
The range that is both in self and other.
Note that ranges that touch but do not overlap return Some(empty range)
and ranges that do not touch and do not overlap return None.
Examples
let left = StrRange::from(0.into()..20.into()); let right = StrRange::from(10.into()..30.into()); assert_eq!( left.intersection(right), Some(StrRange::from(10.into()..20.into())), ); let left = StrRange::from(0.into()..10.into()); let right = StrRange::from(10.into()..20.into()); assert_eq!( left.intersection(right), Some(StrRange::from(10.into()..10.into())), );
pub fn nonempty_intersection(self, other: Self) -> Option<Self>[src]
Like [intersection], but disjoint ranges always return None.
Examples
let left = StrRange::from(0.into()..20.into()); let right = StrRange::from(10.into()..30.into()); assert_eq!( left.nonempty_intersection(right), left.intersection(right), ); let left = StrRange::from(0.into()..10.into()); let right = StrRange::from(10.into()..20.into()); assert_eq!( left.nonempty_intersection(right), None, );
pub fn merge(self, other: Self) -> Self[src]
The range that covers both self and other.
Note that it will also cover any space between self and other.
Example
let left = StrRange::from(0.into()..10.into()); let right = StrRange::from(20.into()..30.into()); assert_eq!( left.merge(right), StrRange::from(0.into()..30.into()), );
pub fn contains(self, other: StrRange) -> bool[src]
Does this range contain other?
other must be completely within self, but may share endpoints.
Examples
let range = StrRange::from(0.into()..20.into()); assert!(range.contains(StrRange::from(5.into()..15.into()))); assert!(range.contains(range));
pub fn contains_exclusive(self, index: StrIndex) -> bool[src]
Does this range contain this index?
This is an exclusive test; use StrIndex::as_unit_range for an inclusive test.
Examples
let range = StrRange::from(10.into()..20.into()); assert!(range.contains_exclusive(range.start())); assert!(!range.contains_exclusive(range.end())); assert!(range.contains(range.end().as_unit_range()));
Trait Implementations
impl From<Range<StrIndex>> for StrRange[src]
impl From<RangeTo<StrIndex>> for StrRange[src]
impl Debug for StrRange[src]
impl Display for StrRange[src]
impl PartialEq<StrRange> for StrRange[src]
impl Eq for StrRange[src]
impl Ord for StrRange[src]
fn cmp(&self, other: &StrRange) -> Ordering[src]
fn max(self, other: Self) -> Self1.21.0[src]
fn min(self, other: Self) -> Self1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self[src]
impl PartialOrd<StrRange> for StrRange[src]
fn partial_cmp(&self, other: &StrRange) -> Option<Ordering>[src]
fn lt(&self, other: &StrRange) -> bool[src]
fn le(&self, other: &StrRange) -> bool[src]
fn gt(&self, other: &StrRange) -> bool[src]
fn ge(&self, other: &StrRange) -> bool[src]
impl Index<StrRange> for str[src]
impl Index<StrRange> for String[src]
impl IndexMut<StrRange> for str[src]
impl IndexMut<StrRange> for String[src]
impl RangeBounds<StrIndex> for StrRange[src]
fn start_bound(&self) -> Bound<&StrIndex>[src]
fn end_bound(&self) -> Bound<&StrIndex>[src]
fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized, 1.35.0[src]
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
impl Hash for StrRange[src]
fn hash<__H: Hasher>(&self, state: &mut __H)[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl Copy for StrRange[src]
impl StructuralPartialEq for StrRange[src]
impl StructuralEq for StrRange[src]
impl Clone for StrRange[src]
fn clone(&self) -> StrRange[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Default for StrRange[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,