1
+ //! Helper traits for Id.
2
+
1
3
use super :: { Id , Owned , Ownership } ;
2
4
use crate :: Message ;
3
5
4
6
/// Helper trait for functionality on slices containing [`Id`]s.
5
- pub trait IdSlice {
7
+ pub trait SliceId {
6
8
/// The type of the items in the slice.
7
9
type Item ;
8
10
9
11
/// Convert a slice of [`Id`]s into a slice of references.
10
12
fn as_slice_ref ( & self ) -> & [ & Self :: Item ] ;
11
13
12
14
/// Convert a mutable slice of [`Id`]s into a mutable slice of references.
13
- fn as_slice_mut_ref ( & mut self ) -> & mut [ & Self :: Item ] ;
15
+ fn as_slice_mut ( & mut self ) -> & mut [ & Self :: Item ] ;
14
16
}
15
17
16
18
/// Helper trait for functionality on slices containing owned [`Id`]s.
17
- pub trait IdSliceMut {
19
+ pub trait SliceIdMut {
18
20
/// The type of the items in the slice.
19
21
type Item ;
20
22
21
23
/// Convert a mutable slice of mutable [`Id`]s into a mutable slice of
22
24
/// mutable references.
23
- fn as_mut_slice_mut_ref ( & mut self ) -> & mut [ & mut Self :: Item ] ;
25
+ fn as_mut_slice_mut ( & mut self ) -> & mut [ & mut Self :: Item ] ;
24
26
}
25
27
26
- impl < T : Message , O : Ownership > IdSlice for [ Id < T , O > ] {
28
+ impl < T : Message , O : Ownership > SliceId for [ Id < T , O > ] {
27
29
type Item = T ;
28
30
29
31
fn as_slice_ref ( & self ) -> & [ & T ] {
@@ -33,18 +35,18 @@ impl<T: Message, O: Ownership> IdSlice for [Id<T, O>] {
33
35
unsafe { & * ptr }
34
36
}
35
37
36
- fn as_slice_mut_ref ( & mut self ) -> & mut [ & T ] {
38
+ fn as_slice_mut ( & mut self ) -> & mut [ & T ] {
37
39
let ptr = self as * mut Self as * mut [ & T ] ;
38
40
// SAFETY: Id<T, O> and &T have the same memory layout. Further safety
39
41
// follows from `Deref` impl.
40
42
unsafe { & mut * ptr }
41
43
}
42
44
}
43
45
44
- impl < T : Message > IdSliceMut for [ Id < T , Owned > ] {
46
+ impl < T : Message > SliceIdMut for [ Id < T , Owned > ] {
45
47
type Item = T ;
46
48
47
- fn as_mut_slice_mut_ref ( & mut self ) -> & mut [ & mut T ] {
49
+ fn as_mut_slice_mut ( & mut self ) -> & mut [ & mut T ] {
48
50
let ptr = self as * mut Self as * mut [ & mut T ] ;
49
51
// SAFETY: Id<T, O> and &mut T have the same memory layout, and the
50
52
// `Id` is `Owned` so we're allowed to hand out mutable references.
0 commit comments