1
- #![ cfg_attr( feature= "const_fn" , feature( const_fn) ) ]
1
+ #![ cfg_attr( feature = "const_fn" , feature( const_fn) ) ]
2
2
3
3
//! Provides wrapper types `Volatile`, `ReadOnly`, `WriteOnly`, `ReadWrite`, which wrap any copy-able type and allows for
4
4
//! volatile memory access to wrapped value. Volatile memory accesses are never optimized away by
@@ -34,7 +34,7 @@ use core::ptr;
34
34
/// take and return copies of the value.
35
35
///
36
36
/// The size of this struct is the same as the size of the contained type.
37
- #[ derive( Debug ) ]
37
+ #[ derive( Debug , Default ) ]
38
38
#[ repr( transparent) ]
39
39
pub struct Volatile < T : Copy > ( T ) ;
40
40
@@ -50,7 +50,7 @@ impl<T: Copy> Volatile<T> {
50
50
/// # Panics
51
51
///
52
52
/// This method never panics.
53
- #[ cfg( feature= "const_fn" ) ]
53
+ #[ cfg( feature = "const_fn" ) ]
54
54
pub const fn new ( value : T ) -> Volatile < T > {
55
55
Volatile ( value)
56
56
}
@@ -66,7 +66,7 @@ impl<T: Copy> Volatile<T> {
66
66
/// # Panics
67
67
///
68
68
/// This method never panics.
69
- #[ cfg( not( feature= "const_fn" ) ) ]
69
+ #[ cfg( not( feature = "const_fn" ) ) ]
70
70
pub fn new ( value : T ) -> Volatile < T > {
71
71
Volatile ( value)
72
72
}
@@ -133,7 +133,8 @@ impl<T: Copy> Volatile<T> {
133
133
///
134
134
/// Ths method never panics.
135
135
pub fn update < F > ( & mut self , f : F )
136
- where F : FnOnce ( & mut T )
136
+ where
137
+ F : FnOnce ( & mut T ) ,
137
138
{
138
139
let mut value = self . read ( ) ;
139
140
f ( & mut value) ;
@@ -150,7 +151,7 @@ impl<T: Copy> Clone for Volatile<T> {
150
151
/// A volatile wrapper which only allows read operations.
151
152
///
152
153
/// The size of this struct is the same as the contained type.
153
- #[ derive( Debug , Clone ) ]
154
+ #[ derive( Debug , Clone , Default ) ]
154
155
pub struct ReadOnly < T : Copy > ( Volatile < T > ) ;
155
156
156
157
impl < T : Copy > ReadOnly < T > {
@@ -207,7 +208,7 @@ impl<T: Copy> ReadOnly<T> {
207
208
/// A volatile wrapper which only allows write operations.
208
209
///
209
210
/// The size of this struct is the same as the contained type.
210
- #[ derive( Debug , Clone ) ]
211
+ #[ derive( Debug , Clone , Default ) ]
211
212
pub struct WriteOnly < T : Copy > ( Volatile < T > ) ;
212
213
213
214
impl < T : Copy > WriteOnly < T > {
@@ -300,7 +301,9 @@ mod tests {
300
301
let volatile_ptr = target_ptr as * mut Volatile < u32 > ;
301
302
302
303
// UNSAFE: Safe, as we know the value exists on the stack.
303
- unsafe { ( * volatile_ptr) . write ( 42u32 ) ; }
304
+ unsafe {
305
+ ( * volatile_ptr) . write ( 42u32 ) ;
306
+ }
304
307
305
308
assert_eq ! ( target_value, 42u32 ) ;
306
309
}
0 commit comments