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