@@ -345,11 +345,11 @@ impl<'a, B: BitmapSlice> VolatileSlice<'a, B> {
345
345
/// assert_eq!(8, start.len());
346
346
/// assert_eq!(24, end.len());
347
347
/// ```
348
- pub fn split_at ( self , mid : usize ) -> Result < ( Self , Self ) > {
348
+ pub fn split_at ( & self , mid : usize ) -> Result < ( Self , Self ) > {
349
349
let end = self . offset ( mid) ?;
350
350
let start = unsafe {
351
351
// safe because self.offset() already checked the bounds
352
- VolatileSlice :: with_bitmap ( self . addr , mid, self . bitmap )
352
+ VolatileSlice :: with_bitmap ( self . addr , mid, self . bitmap . clone ( ) )
353
353
} ;
354
354
355
355
Ok ( ( start, end) )
@@ -360,7 +360,7 @@ impl<'a, B: BitmapSlice> VolatileSlice<'a, B> {
360
360
///
361
361
/// The returned subslice is a copy of this slice with the address increased by `offset` bytes
362
362
/// and the size set to `count` bytes.
363
- pub fn subslice ( self , offset : usize , count : usize ) -> Result < Self > {
363
+ pub fn subslice ( & self , offset : usize , count : usize ) -> Result < Self > {
364
364
let mem_end = compute_offset ( offset, count) ?;
365
365
if mem_end > self . len ( ) {
366
366
return Err ( Error :: OutOfBounds { addr : mem_end } ) ;
@@ -381,7 +381,7 @@ impl<'a, B: BitmapSlice> VolatileSlice<'a, B> {
381
381
///
382
382
/// The returned subslice is a copy of this slice with the address increased by `count` bytes
383
383
/// and the size reduced by `count` bytes.
384
- pub fn offset ( self , count : usize ) -> Result < VolatileSlice < ' a , B > > {
384
+ pub fn offset ( & self , count : usize ) -> Result < VolatileSlice < ' a , B > > {
385
385
let new_addr = ( self . addr as usize )
386
386
. checked_add ( count)
387
387
. ok_or ( Error :: Overflow {
@@ -953,7 +953,7 @@ where
953
953
}
954
954
955
955
/// Returns a pointer to the underlying memory.
956
- pub fn as_ptr ( self ) -> * mut u8 {
956
+ pub fn as_ptr ( & self ) -> * mut u8 {
957
957
self . addr as * mut u8
958
958
}
959
959
@@ -968,7 +968,7 @@ where
968
968
/// let v_ref = unsafe { VolatileRef::<u32>::new(0 as *mut _) };
969
969
/// assert_eq!(v_ref.len(), size_of::<u32>() as usize);
970
970
/// ```
971
- pub fn len ( self ) -> usize {
971
+ pub fn len ( & self ) -> usize {
972
972
size_of :: < T > ( )
973
973
}
974
974
@@ -979,14 +979,14 @@ where
979
979
980
980
/// Does a volatile write of the value `v` to the address of this ref.
981
981
#[ inline( always) ]
982
- pub fn store ( self , v : T ) {
982
+ pub fn store ( & self , v : T ) {
983
983
unsafe { write_volatile ( self . addr , Packed :: < T > ( v) ) } ;
984
984
self . bitmap . mark_dirty ( 0 , size_of :: < T > ( ) )
985
985
}
986
986
987
987
/// Does a volatile read of the value at the address of this ref.
988
988
#[ inline( always) ]
989
- pub fn load ( self ) -> T {
989
+ pub fn load ( & self ) -> T {
990
990
// For the purposes of demonstrating why read_volatile is necessary, try replacing the code
991
991
// in this function with the commented code below and running `cargo test --release`.
992
992
// unsafe { *(self.addr as *const T) }
@@ -995,8 +995,10 @@ where
995
995
996
996
/// Converts this to a [`VolatileSlice`](struct.VolatileSlice.html) with the same size and
997
997
/// address.
998
- pub fn to_slice ( self ) -> VolatileSlice < ' a , B > {
999
- unsafe { VolatileSlice :: with_bitmap ( self . addr as * mut u8 , size_of :: < T > ( ) , self . bitmap ) }
998
+ pub fn to_slice ( & self ) -> VolatileSlice < ' a , B > {
999
+ unsafe {
1000
+ VolatileSlice :: with_bitmap ( self . addr as * mut u8 , size_of :: < T > ( ) , self . bitmap . clone ( ) )
1001
+ }
1000
1002
}
1001
1003
}
1002
1004
@@ -1122,7 +1124,11 @@ where
1122
1124
/// Converts this to a `VolatileSlice` with the same size and address.
1123
1125
pub fn to_slice ( & self ) -> VolatileSlice < ' a , B > {
1124
1126
unsafe {
1125
- VolatileSlice :: with_bitmap ( self . addr , self . nelem * self . element_size ( ) , self . bitmap )
1127
+ VolatileSlice :: with_bitmap (
1128
+ self . addr ,
1129
+ self . nelem * self . element_size ( ) ,
1130
+ self . bitmap . clone ( ) ,
1131
+ )
1126
1132
}
1127
1133
}
1128
1134
0 commit comments