scsys_traits/convert.rs
1/*
2 Appellation: specs <module>
3 Contrib: FL03 <jo3mccain@icloud.com>
4*/
5/// [`AsSlice`] is a generic trait for converting a type into a slice of its
6/// elements. This is useful for types that can be represented as a contiguous sequence of
7/// elements, such as arrays, vectors, or other collections.
8pub trait AsSlice<T> {
9 private!();
10
11 fn as_slice(&self) -> &[T];
12}
13/// [`AsSliceMut`] is a generic trait for converting a type into a mutable slice of its
14/// elements.
15pub trait AsSliceMut<T> {
16 private!();
17 /// converts the type into a mutable slice of its elements.
18 fn as_mut_slice(&mut self) -> &mut [T];
19}
20
21/*
22 ************* Implementations *************
23*/
24impl<S, T> AsSlice<T> for S
25where
26 S: AsRef<[T]>,
27{
28 seal!();
29
30 fn as_slice(&self) -> &[T] {
31 self.as_ref()
32 }
33}
34
35impl<S, T> AsSliceMut<T> for S
36where
37 S: AsMut<[T]>,
38{
39 seal!();
40
41 fn as_mut_slice(&mut self) -> &mut [T] {
42 self.as_mut()
43 }
44}