@@ -2,7 +2,7 @@ use crate::{
2
2
access:: { Access , Copyable , ReadOnly , ReadWrite , WriteOnly } ,
3
3
volatile_ptr:: VolatilePtr ,
4
4
} ;
5
- use core:: { fmt, marker:: PhantomData , ptr:: NonNull } ;
5
+ use core:: { cmp :: Ordering , fmt, hash , marker:: PhantomData , ptr:: NonNull } ;
6
6
7
7
/// Volatile pointer type that respects Rust's aliasing rules.
8
8
///
@@ -12,6 +12,9 @@ use core::{fmt, marker::PhantomData, ptr::NonNull};
12
12
/// - only read-only types implement [`Clone`] and [`Copy`]
13
13
/// - [`Send`] and [`Sync`] are implemented if `T: Sync`
14
14
///
15
+ /// However, trait implementations like [`fmt::Debug`] and [`Eq`] behave like they do on pointer
16
+ /// types and don't access the referenced value.
17
+ ///
15
18
/// To perform volatile operations on `VolatileRef` types, use the [`as_ptr`][Self::as_ptr]
16
19
/// or [`as_mut_ptr`](Self::as_mut_ptr) methods to create a temporary
17
20
/// [`VolatilePtr`][crate::VolatilePtr] instance.
@@ -239,7 +242,7 @@ unsafe impl<T, A> Sync for VolatileRef<'_, T, A> where T: Sync {}
239
242
240
243
impl < T , A > fmt:: Debug for VolatileRef < ' _ , T , A >
241
244
where
242
- T : Copy + fmt :: Debug + ?Sized ,
245
+ T : ?Sized ,
243
246
{
244
247
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
245
248
f. debug_struct ( "VolatileRef" )
@@ -248,3 +251,50 @@ where
248
251
. finish ( )
249
252
}
250
253
}
254
+
255
+ impl < T , A > fmt:: Pointer for VolatileRef < ' _ , T , A >
256
+ where
257
+ T : ?Sized ,
258
+ {
259
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
260
+ fmt:: Pointer :: fmt ( & self . pointer . as_ptr ( ) , f)
261
+ }
262
+ }
263
+
264
+ impl < T , A > PartialEq for VolatileRef < ' _ , T , A >
265
+ where
266
+ T : ?Sized ,
267
+ {
268
+ fn eq ( & self , other : & Self ) -> bool {
269
+ core:: ptr:: eq ( self . pointer . as_ptr ( ) , other. pointer . as_ptr ( ) )
270
+ }
271
+ }
272
+
273
+ impl < T , A > Eq for VolatileRef < ' _ , T , A > where T : ?Sized { }
274
+
275
+ impl < T , A > PartialOrd for VolatileRef < ' _ , T , A >
276
+ where
277
+ T : ?Sized ,
278
+ {
279
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
280
+ Some ( Ord :: cmp ( & self . pointer . as_ptr ( ) , & other. pointer . as_ptr ( ) ) )
281
+ }
282
+ }
283
+
284
+ impl < T , A > Ord for VolatileRef < ' _ , T , A >
285
+ where
286
+ T : ?Sized ,
287
+ {
288
+ fn cmp ( & self , other : & Self ) -> Ordering {
289
+ Ord :: cmp ( & self . pointer . as_ptr ( ) , & other. pointer . as_ptr ( ) )
290
+ }
291
+ }
292
+
293
+ impl < T , A > hash:: Hash for VolatileRef < ' _ , T , A >
294
+ where
295
+ T : ?Sized ,
296
+ {
297
+ fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
298
+ self . pointer . as_ptr ( ) . hash ( state) ;
299
+ }
300
+ }
0 commit comments