std_traits/
slice.rs

1use crate::primitive::Primitive;
2
3pub trait Slice: Primitive + AsRef<[Self::Item]> {
4    type Item;
5
6    fn as_slice(&self) -> &[Self::Item];
7}
8
9impl<T> Primitive for [T] {}
10impl<T> Slice for [T] {
11    type Item = T;
12
13    fn as_slice(&self) -> &[Self::Item] {
14        self
15    }
16}
17
18impl Primitive for str {}
19impl Slice for str {
20    type Item = u8;
21
22    fn as_slice(&self) -> &[Self::Item] {
23        self.as_bytes()
24    }
25}