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