pub fn try_slice<R>(&self, range: R) -> Option<Self>
    where
        R: RangeBounds<usize>,
    {
        let start = match range.start_bound() {
            Bound::Included(&position) => position,
            Bound::Excluded(position) => position.saturating_add(1),
            Bound::Unbounded => 0,
        };

        let end = match range.end_bound() {
            Bound::Included(position) => position.saturating_add(1),
            Bound::Excluded(&position) => position,
            Bound::Unbounded => self.len(),
        };

        if start <= self.length && end <= self.length && start <= end {
            let start_loc = Location::new(
                self.start.source().clone(),
                self.start.position() + start,
            );
            Some(Self::new(start_loc, end - start))
        } else {
            None
        }
    }
/// Slices this span to the given range. Returns `None` if the range is
/// invalid.
Slices this span to the given range. Returns `None` if the range is
invalid.
Slices this span to the given range . Returns ` None ` if the range is invalid .
pub fn try_slice<R>(&self, range: R) -> Option<Self>
    where
        R: RangeBounds<usize>,
    {
        let start = match range.start_bound() {
            Bound::Included(&position) => position,
            Bound::Excluded(position) => position.saturating_add(1),
            Bound::Unbounded => 0,
        };
        let end = match range.end_bound() {
            Bound::Included(position) => position.saturating_add(1),
            Bound::Excluded(&position) => position,
            Bound::Unbounded => self.len(),
        };
        if start <= self.length && end <= self.length && start <= end {
            let start_loc = Location::new(
                self.start.source().clone(),
                self.start.position() + start,
            );
            Some(Self::new(start_loc, end - start))
        } else {
            None
        }
    }
pub fn try_slice < R > ( & self , range : R ) -> Option < Self > where R : RangeBounds < usize > , { let start = match range . start_bound ( ) { Bound :: Included ( & position ) => position , Bound :: Excluded ( position ) => position . saturating_add ( 1 ) , Bound :: Unbounded => 0 , } ; let end = match range . end_bound ( ) { Bound :: Included ( position ) => position . saturating_add ( 1 ) , Bound :: Excluded ( & position ) => position , Bound :: Unbounded => self . len ( ) , } ; if start <= self . length && end <= self . length && start <= end { let start_loc = Location :: new ( self . start . source ( ) . clone ( ) , self . start . position ( ) + start , ) ; Some ( Self :: new ( start_loc , end - start ) ) } else { None } }
Slices this span to the given range.
Slices this span to the given range .
&self
range
R
&self
range
R