    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25

    //! Extension for slices.

    /// Represents a type that can be referenced as a slice.
    pub trait AsSlice<T> {
        /// Returns a reference to the underlying slice.
        fn as_slice(&self) -> &[T];
    }

    impl<T> AsSlice<T> for [T] {
        fn as_slice(&self) -> &[T] {
            self
        }
    }

    impl<T> AsSlice<T> for &[T] {
        fn as_slice(&self) -> &[T] {
            *self
        }
    }

    impl<T> AsSlice<T> for Vec<T> {
        fn as_slice(&self) -> &[T] {
            self.as_slice()
        }
    }