@@ -13,8 +13,20 @@ pub trait Projectable: Sized {
13
13
type Inner : ?Sized ;
14
14
}
15
15
16
+ /// Marks project operations as safe.
17
+ ///
18
+ /// # Safety
19
+ ///
20
+ /// * The `@base->field` and `@mut base->field` operations implemented by the [`Project`] and
21
+ /// [`ProjectMut`] traits must not have additional safety requirements.
22
+ pub unsafe trait SafeProject : Projectable { }
23
+
16
24
/// Shared projection operation `@base->field`.
17
- pub trait Project < F > : Projectable
25
+ ///
26
+ /// # Safety
27
+ ///
28
+ ///
29
+ pub unsafe trait Project < F > : Projectable
18
30
where
19
31
F : UnalignedField < Base = Self :: Inner > ,
20
32
{
@@ -28,13 +40,20 @@ where
28
40
/// # Safety
29
41
///
30
42
/// * `this` must be a dereferenceable pointer pointing at a valid value of `Self`.
43
+ /// * for the duration of `'a`, the value at `this` is only used by other projection
44
+ /// operations.
45
+ /// * for the duration of `'a`, the value at `this` is not mutably projected with `F`.
31
46
unsafe fn project < ' a > ( this : * const Self ) -> Self :: Output < ' a >
32
47
where
33
48
Self : ' a ;
34
49
}
35
50
36
51
/// Exclusive projection operation `@mut base->field`.
37
- pub trait ProjectMut < F > : Projectable
52
+ ///
53
+ /// # Safety
54
+ ///
55
+ ///
56
+ pub unsafe trait ProjectMut < F > : Projectable
38
57
where
39
58
F : UnalignedField < Base = Self :: Inner > ,
40
59
{
@@ -48,19 +67,13 @@ where
48
67
/// # Safety
49
68
///
50
69
/// * `this` must be a dereferenceable pointer pointing at a valid value of `Self`.
51
- /// * this function must only be called once.
70
+ /// * for the duration of `'a`, the value at `this` is only used by other projection
71
+ /// operations for fields other than `F`.
52
72
unsafe fn project_mut < ' a > ( this : * mut Self ) -> Self :: OutputMut < ' a >
53
73
where
54
74
Self : ' a ;
55
75
}
56
76
57
- /// Marks project operations as safe.
58
- ///
59
- /// # Safety
60
- ///
61
- /// * the `@base->field` and `@mut base->field` operations must be safe.
62
- pub unsafe trait SafeProject : Projectable { }
63
-
64
77
include ! ( "./projections/maybe_uninit.rs" ) ;
65
78
include ! ( "./projections/non_null.rs" ) ;
66
79
include ! ( "./projections/pin.rs" ) ;
0 commit comments