@@ -25,41 +25,47 @@ pub mod atomic {
25
25
pub use portable_atomic:: * ;
26
26
}
27
27
28
- use core:: pin:: Pin ;
29
-
30
28
#[ cfg( CONFIG_RUST_ALLOC ) ]
31
29
pub use portable_atomic_util:: Arc ;
32
30
#[ cfg( CONFIG_RUST_ALLOC ) ]
33
31
pub use portable_atomic_util:: Weak ;
34
32
35
- /// Safe Pinned Weak references.
36
- ///
37
- /// Pin<Arc<T>> can't be converted to/from Weak safely, because there is know way to know if a given
38
- /// weak reference came from a pinned Arc. This wraps the weak reference in a new type so we know
39
- /// that it came from a pinned Arc.
40
- ///
41
- /// There is a pin-weak crate that provides this for `std::sync::Arc`, but not for the one in the
42
- /// portable-atomic-utils crate.
43
- pub struct PinWeak < T > ( Weak < T > ) ;
33
+ #[ cfg( CONFIG_RUST_ALLOC ) ]
34
+ mod pinweak {
35
+ use core:: pin:: Pin ;
44
36
45
- impl < T > PinWeak < T > {
46
- /// Downgrade an `Pin<Arc<T>>` into a `PinWeak`.
37
+ /// Safe Pinned Weak references.
47
38
///
48
- /// This would be easier to use if it could be added to Arc.
49
- pub fn downgrade ( this : Pin < Arc < T > > ) -> Self {
50
- // SAFETY: we will never return anything other than a Pin<Arc<T>>.
51
- Self ( Arc :: downgrade ( & unsafe { Pin :: into_inner_unchecked ( this) } ) )
52
- }
39
+ /// Pin<Arc<T>> can't be converted to/from Weak safely, because there is know way to know if a given
40
+ /// weak reference came from a pinned Arc. This wraps the weak reference in a new type so we know
41
+ /// that it came from a pinned Arc.
42
+ ///
43
+ /// There is a pin-weak crate that provides this for `std::sync::Arc`, but not for the one in the
44
+ /// portable-atomic-utils crate.
45
+ pub struct PinWeak < T > ( Weak < T > ) ;
53
46
54
- /// Upgrade back to a `Pin<Arc<T>>`.
55
- pub fn upgrade ( & self ) -> Option < Pin < Arc < T > > > {
56
- // SAFETY: The weak was only constructed from a `Pin<Arc<T>>`.
57
- self . 0
58
- . upgrade ( )
59
- . map ( |arc| unsafe { Pin :: new_unchecked ( arc) } )
47
+ impl < T > PinWeak < T > {
48
+ /// Downgrade an `Pin<Arc<T>>` into a `PinWeak`.
49
+ ///
50
+ /// This would be easier to use if it could be added to Arc.
51
+ pub fn downgrade ( this : Pin < Arc < T > > ) -> Self {
52
+ // SAFETY: we will never return anything other than a Pin<Arc<T>>.
53
+ Self ( Arc :: downgrade ( & unsafe { Pin :: into_inner_unchecked ( this) } ) )
54
+ }
55
+
56
+ /// Upgrade back to a `Pin<Arc<T>>`.
57
+ pub fn upgrade ( & self ) -> Option < Pin < Arc < T > > > {
58
+ // SAFETY: The weak was only constructed from a `Pin<Arc<T>>`.
59
+ self . 0
60
+ . upgrade ( )
61
+ . map ( |arc| unsafe { Pin :: new_unchecked ( arc) } )
62
+ }
60
63
}
61
64
}
62
65
66
+ #[ cfg( CONFIG_RUST_ALLOC ) ]
67
+ pub use pinweak:: * ;
68
+
63
69
mod mutex;
64
70
65
71
pub use mutex:: { Condvar , LockResult , Mutex , MutexGuard , TryLockError , TryLockResult } ;
0 commit comments