/// Returns a slice of self for the provided range.
///
/// This will increment the reference count for the underlying memory and
/// return a new `Bytes` handle set to the slice.
///
/// This operation is `O(1)`.
///
/// # Examples
///
/// ```
/// use bytes::Bytes;
///
/// let a = Bytes::from(&b"hello world"[..]);
/// let b = a.slice(2..5);
///
/// assert_eq!(&b[..], b"llo");
/// ```
///
/// # Panics
///
/// Requires that `begin <= end` and `end <= self.len()`, otherwise slicing
/// will panic.
Returns a slice of self for the provided range.
This will increment the reference count for the underlying memory and
return a new `Bytes` handle set to the slice.


Returns a slice of self for the provided range . This will increment the reference count for the underlying memory and return a new ` Bytes ` handle set to the slice .
pub fn slice(&self, range: impl RangeBounds<usize>) -> Bytes {
        use core::ops::Bound;
        let len = self.len();
        let begin = match range.start_bound() {
            Bound::Included(&n) => n,
            Bound::Excluded(&n) => n + 1,
            Bound::Unbounded => 0,
        };
        let end = match range.end_bound() {
            Bound::Included(&n) => n + 1,
            Bound::Excluded(&n) => n,
            Bound::Unbounded => len,
        };
        assert!(
            begin <= end,
            "range start must not be greater than end: {:?} <= {:?}",
            begin,
            end,
        );
        assert!(
            end <= len,
            "range end out of bounds: {:?} <= {:?}",
            end,
            len,
        );
        if end == begin {
            return Bytes::new();
        }
        let mut ret = self.clone();
        ret.len = end - begin;
        ret.ptr = unsafe { ret.ptr.offset(begin as isize) };
        ret
    }
pub fn slice ( & self , range : impl RangeBounds < usize > ) -> Bytes { use core :: ops :: Bound ; let len = self . len ( ) ; let begin = match range . start_bound ( ) { Bound :: Included ( & n ) => n , Bound :: Excluded ( & n ) => n + 1 , Bound :: Unbounded => 0 , } ; let end = match range . end_bound ( ) { Bound :: Included ( & n ) => n + 1 , Bound :: Excluded ( & n ) => n , Bound :: Unbounded => len , } ; assert ! ( begin end " " begin end ) ; assert ! ( end len " " end len ) ; if end == begin { return Bytes :: new ( ) ; } let mut ret = self . clone ( ) ; ret . len = end - begin ; ret . ptr = unsafe { ret . ptr . offset ( begin as isize ) } ; ret }
Returns a slice of self for the provided range.
Returns a slice of self for the provided range .
&self
range
impl RangeBounds<usize>
examples
```
use bytes::Bytes.




` ` ` use bytes :: Bytes .
panics
Requires that `begin <= end` and `end <= self.len()`, otherwise slicing
will panic.
Requires that ` begin < = end ` and ` end < = self . len () ` otherwise slicing will panic .