1#![deny(missing_docs)]
17#![deny(warnings)]
18#![no_std]
19
20extern crate stable_deref_trait;
21
22pub trait AsSlice {
24 type Element;
26
27 fn as_slice(&self) -> &[Self::Element];
29}
30
31pub trait AsMutSlice: AsSlice {
33 fn as_mut_slice(&mut self) -> &mut [Self::Element];
35}
36
37impl<'a, S> AsSlice for &'a S
38where
39 S: ?Sized + AsSlice,
40{
41 type Element = S::Element;
42
43 fn as_slice(&self) -> &[S::Element] {
44 (**self).as_slice()
45 }
46}
47
48impl<'a, S> AsSlice for &'a mut S
49where
50 S: ?Sized + AsSlice,
51{
52 type Element = S::Element;
53
54 fn as_slice(&self) -> &[S::Element] {
55 (**self).as_slice()
56 }
57}
58
59impl<'a, S> AsMutSlice for &'a mut S
60where
61 S: ?Sized + AsMutSlice,
62{
63 fn as_mut_slice(&mut self) -> &mut [S::Element] {
64 (**self).as_mut_slice()
65 }
66}
67
68impl<T> AsSlice for [T] {
69 type Element = T;
70
71 fn as_slice(&self) -> &[T] {
72 self
73 }
74}
75
76impl<T> AsMutSlice for [T] {
77 fn as_mut_slice(&mut self) -> &mut [T] {
78 self
79 }
80}
81
82impl<T, const N: usize> AsSlice for [T; N] {
83 type Element = T;
84
85 fn as_slice(&self) -> &[T] {
86 self
87 }
88}
89
90impl<T, const N: usize> AsMutSlice for [T; N] {
91 fn as_mut_slice(&mut self) -> &mut [T] {
92 self
93 }
94}