@@ -207,7 +207,7 @@ where
207
207
/// let mut_reference = unsafe { VolatilePtr::new_read_write(NonNull::from(&mut value)) };
208
208
/// assert_eq!(mut_reference.read(), 50);
209
209
/// ```
210
- pub fn read ( & self ) -> T
210
+ pub fn read ( self ) -> T
211
211
where
212
212
R : access:: Safe ,
213
213
{
@@ -234,7 +234,7 @@ where
234
234
///
235
235
/// assert_eq!(volatile.read(), 50);
236
236
/// ```
237
- pub fn write ( & mut self , value : T )
237
+ pub fn write ( self , value : T )
238
238
where
239
239
W : access:: Safe ,
240
240
{
@@ -259,7 +259,7 @@ where
259
259
///
260
260
/// assert_eq!(volatile.read(), 43);
261
261
/// ```
262
- pub fn update < F > ( & mut self , f : F )
262
+ pub fn update < F > ( self , f : F )
263
263
where
264
264
R : access:: Safe ,
265
265
W : access:: Safe ,
@@ -300,13 +300,13 @@ where
300
300
///
301
301
/// assert_eq!(unsafe { *unwrapped }, 50); // non volatile access, be careful!
302
302
/// ```
303
- pub fn as_ptr ( & self ) -> NonNull < T > {
303
+ pub fn as_ptr ( self ) -> NonNull < T > {
304
304
self . pointer
305
305
}
306
306
}
307
307
308
308
/// Transformation methods for accessing struct fields
309
- impl < T , R , W > VolatilePtr < ' _ , T , Access < R , W > >
309
+ impl < ' a , T , R , W > VolatilePtr < ' a , T , Access < R , W > >
310
310
where
311
311
T : ?Sized ,
312
312
{
@@ -351,7 +351,7 @@ where
351
351
/// value
352
352
/// })};
353
353
/// ```
354
- pub unsafe fn map < ' a , F , U > ( & ' a self , f : F ) -> VolatilePtr < ' a , U , Access < R , access:: NoAccess > >
354
+ pub unsafe fn map < F , U > ( self , f : F ) -> VolatilePtr < ' a , U , Access < R , access:: NoAccess > >
355
355
where
356
356
F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
357
357
U : ?Sized ,
@@ -360,8 +360,8 @@ where
360
360
}
361
361
362
362
#[ cfg( feature = "very_unstable" ) ]
363
- pub const unsafe fn map_const < ' a , F , U > (
364
- & ' a self ,
363
+ pub const unsafe fn map_const < F , U > (
364
+ self ,
365
365
f : F ,
366
366
) -> VolatilePtr < ' a , U , Access < R , access:: NoAccess > >
367
367
where
@@ -371,7 +371,7 @@ where
371
371
unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
372
372
}
373
373
374
- pub unsafe fn map_mut < F , U > ( & mut self , f : F ) -> VolatilePtr < U , Access < R , W > >
374
+ pub unsafe fn map_mut < F , U > ( self , f : F ) -> VolatilePtr < ' a , U , Access < R , W > >
375
375
where
376
376
F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
377
377
U : ?Sized ,
@@ -380,7 +380,7 @@ where
380
380
}
381
381
382
382
#[ cfg( feature = "very_unstable" ) ]
383
- pub const unsafe fn map_mut_const < F , U > ( & mut self , f : F ) -> VolatilePtr < U , Access < R , W > >
383
+ pub const unsafe fn map_mut_const < F , U > ( self , f : F ) -> VolatilePtr < ' a , U , Access < R , W > >
384
384
where
385
385
F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
386
386
U : ?Sized ,
@@ -392,7 +392,7 @@ where
392
392
/// Methods for volatile slices
393
393
#[ cfg( feature = "unstable" ) ]
394
394
impl < ' a , T , R , W > VolatilePtr < ' a , [ T ] , Access < R , W > > {
395
- pub fn len ( & self ) -> usize {
395
+ pub fn len ( self ) -> usize {
396
396
self . pointer . len ( )
397
397
}
398
398
@@ -433,9 +433,9 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
433
433
/// assert_eq!(subslice.index(0).read(), 2);
434
434
/// ```
435
435
pub fn index < I > (
436
- & self ,
436
+ self ,
437
437
index : I ,
438
- ) -> VolatilePtr < <I as SliceIndex < [ T ] > >:: Output , Access < R , access:: NoAccess > >
438
+ ) -> VolatilePtr < ' a , <I as SliceIndex < [ T ] > >:: Output , Access < R , access:: NoAccess > >
439
439
where
440
440
I : SliceIndex < [ T ] > + SliceIndex < [ ( ) ] > + Clone ,
441
441
{
@@ -445,7 +445,10 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
445
445
}
446
446
447
447
#[ cfg( feature = "very_unstable" ) ]
448
- pub const fn index_const ( & self , index : usize ) -> VolatilePtr < T , Access < R , access:: NoAccess > > {
448
+ pub const fn index_const (
449
+ self ,
450
+ index : usize ,
451
+ ) -> VolatilePtr < ' a , T , Access < R , access:: NoAccess > > {
449
452
assert ! ( index < self . pointer. len( ) , "index out of bounds" ) ;
450
453
unsafe {
451
454
self . map_const ( |slice| {
@@ -455,9 +458,9 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
455
458
}
456
459
457
460
pub fn index_mut < I > (
458
- & mut self ,
461
+ self ,
459
462
index : I ,
460
- ) -> VolatilePtr < <I as SliceIndex < [ T ] > >:: Output , Access < R , W > >
463
+ ) -> VolatilePtr < ' a , <I as SliceIndex < [ T ] > >:: Output , Access < R , W > >
461
464
where
462
465
I : SliceIndex < [ T ] > + SliceIndex < [ ( ) ] > + Clone ,
463
466
{
@@ -467,7 +470,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
467
470
}
468
471
469
472
#[ cfg( feature = "very_unstable" ) ]
470
- pub const fn index_mut_const ( & mut self , index : usize ) -> VolatilePtr < T , Access < R , W > > {
473
+ pub const fn index_mut_const ( self , index : usize ) -> VolatilePtr < ' a , T , Access < R , W > > {
471
474
assert ! ( index < self . pointer. len( ) , "index out of bounds" ) ;
472
475
unsafe {
473
476
self . map_mut_const ( |slice| {
@@ -510,7 +513,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
510
513
/// assert_eq!(src, [1, 2]);
511
514
/// assert_eq!(dst, [5, 1, 2]);
512
515
/// ```
513
- pub fn copy_into_slice ( & self , dst : & mut [ T ] )
516
+ pub fn copy_into_slice ( self , dst : & mut [ T ] )
514
517
where
515
518
T : Copy ,
516
519
{
@@ -566,7 +569,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
566
569
/// assert_eq!(src, [1, 2, 3, 4]);
567
570
/// assert_eq!(dst, [3, 4]);
568
571
/// ```
569
- pub fn copy_from_slice ( & mut self , src : & [ T ] )
572
+ pub fn copy_from_slice ( self , src : & [ T ] )
570
573
where
571
574
T : Copy ,
572
575
{
@@ -619,7 +622,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
619
622
/// volatile.copy_within(1..5, 8);
620
623
///
621
624
/// assert_eq!(&byte_array, b"Hello, Wello!");
622
- pub fn copy_within ( & mut self , src : impl RangeBounds < usize > , dest : usize )
625
+ pub fn copy_within ( self , src : impl RangeBounds < usize > , dest : usize )
623
626
where
624
627
T : Copy ,
625
628
{
@@ -643,11 +646,11 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
643
646
}
644
647
645
648
pub fn split_at (
646
- & self ,
649
+ self ,
647
650
mid : usize ,
648
651
) -> (
649
- VolatilePtr < [ T ] , Access < R , access:: NoAccess > > ,
650
- VolatilePtr < [ T ] , Access < R , access:: NoAccess > > ,
652
+ VolatilePtr < ' a , [ T ] , Access < R , access:: NoAccess > > ,
653
+ VolatilePtr < ' a , [ T ] , Access < R , access:: NoAccess > > ,
651
654
) {
652
655
assert ! ( mid <= self . pointer. len( ) ) ;
653
656
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
@@ -656,11 +659,11 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
656
659
}
657
660
658
661
pub fn split_at_mut (
659
- & mut self ,
662
+ self ,
660
663
mid : usize ,
661
664
) -> (
662
- VolatilePtr < [ T ] , Access < R , W > > ,
663
- VolatilePtr < [ T ] , Access < R , W > > ,
665
+ VolatilePtr < ' a , [ T ] , Access < R , W > > ,
666
+ VolatilePtr < ' a , [ T ] , Access < R , W > > ,
664
667
) {
665
668
assert ! ( mid <= self . pointer. len( ) ) ;
666
669
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
@@ -669,11 +672,11 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
669
672
}
670
673
671
674
unsafe fn split_at_unchecked (
672
- & self ,
675
+ self ,
673
676
mid : usize ,
674
677
) -> (
675
- VolatilePtr < [ T ] , Access < R , access:: NoAccess > > ,
676
- VolatilePtr < [ T ] , Access < R , access:: NoAccess > > ,
678
+ VolatilePtr < ' a , [ T ] , Access < R , access:: NoAccess > > ,
679
+ VolatilePtr < ' a , [ T ] , Access < R , access:: NoAccess > > ,
677
680
) {
678
681
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
679
682
unsafe {
@@ -685,11 +688,11 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
685
688
}
686
689
687
690
unsafe fn split_at_mut_unchecked (
688
- & mut self ,
691
+ self ,
689
692
mid : usize ,
690
693
) -> (
691
- VolatilePtr < [ T ] , Access < R , W > > ,
692
- VolatilePtr < [ T ] , Access < R , W > > ,
694
+ VolatilePtr < ' a , [ T ] , Access < R , W > > ,
695
+ VolatilePtr < ' a , [ T ] , Access < R , W > > ,
693
696
) {
694
697
let len = self . pointer . len ( ) ;
695
698
let ptr = self . pointer . as_mut_ptr ( ) ;
@@ -711,10 +714,10 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
711
714
}
712
715
713
716
pub fn as_chunks < const N : usize > (
714
- & self ,
717
+ self ,
715
718
) -> (
716
- VolatilePtr < [ [ T ; N ] ] , Access < R , access:: NoAccess > > ,
717
- VolatilePtr < [ T ] , Access < R , access:: NoAccess > > ,
719
+ VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , access:: NoAccess > > ,
720
+ VolatilePtr < ' a , [ T ] , Access < R , access:: NoAccess > > ,
718
721
) {
719
722
assert_ne ! ( N , 0 ) ;
720
723
let len = self . pointer . len ( ) / N ;
@@ -726,8 +729,8 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
726
729
}
727
730
728
731
pub unsafe fn as_chunks_unchecked < const N : usize > (
729
- & self ,
730
- ) -> VolatilePtr < [ [ T ; N ] ] , Access < R , access:: NoAccess > > {
732
+ self ,
733
+ ) -> VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , access:: NoAccess > > {
731
734
debug_assert_ne ! ( N , 0 ) ;
732
735
debug_assert_eq ! ( self . pointer. len( ) % N , 0 ) ;
733
736
let new_len =
@@ -744,10 +747,10 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
744
747
}
745
748
746
749
pub fn as_chunks_mut < const N : usize > (
747
- & mut self ,
750
+ self ,
748
751
) -> (
749
- VolatilePtr < [ [ T ; N ] ] , Access < R , W > > ,
750
- VolatilePtr < [ T ] , Access < R , W > > ,
752
+ VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , W > > ,
753
+ VolatilePtr < ' a , [ T ] , Access < R , W > > ,
751
754
) {
752
755
assert_ne ! ( N , 0 ) ;
753
756
let len = self . pointer . len ( ) / N ;
@@ -759,8 +762,8 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
759
762
}
760
763
761
764
pub unsafe fn as_chunks_unchecked_mut < const N : usize > (
762
- & mut self ,
763
- ) -> VolatilePtr < [ [ T ; N ] ] , Access < R , W > > {
765
+ self ,
766
+ ) -> VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , W > > {
764
767
debug_assert_ne ! ( N , 0 ) ;
765
768
debug_assert_eq ! ( self . pointer. len( ) % N , 0 ) ;
766
769
let new_len =
@@ -819,7 +822,7 @@ impl<A> VolatilePtr<'_, [u8], A> {
819
822
/// buf.fill(1);
820
823
/// assert_eq!(unsafe { buf.as_ptr().as_mut() }, &mut vec![1; 10]);
821
824
/// ```
822
- pub fn fill ( & mut self , value : u8 ) {
825
+ pub fn fill ( self , value : u8 ) {
823
826
unsafe {
824
827
intrinsics:: volatile_set_memory ( self . pointer . as_mut_ptr ( ) , value, self . pointer . len ( ) ) ;
825
828
}
@@ -831,7 +834,7 @@ impl<A> VolatilePtr<'_, [u8], A> {
831
834
/// These methods are only available with the `unstable` feature enabled (requires a nightly
832
835
/// Rust compiler).
833
836
#[ cfg( feature = "unstable" ) ]
834
- impl < T , R , W , const N : usize > VolatilePtr < ' _ , [ T ; N ] , Access < R , W > > {
837
+ impl < ' a , T , R , W , const N : usize > VolatilePtr < ' a , [ T ; N ] , Access < R , W > > {
835
838
/// Converts an array reference to a shared slice.
836
839
///
837
840
/// This makes it possible to use the methods defined on slices.
@@ -856,7 +859,7 @@ impl<T, R, W, const N: usize> VolatilePtr<'_, [T; N], Access<R, W>> {
856
859
///
857
860
/// assert_eq!(dst, [1, 2]);
858
861
/// ```
859
- pub fn as_slice ( & self ) -> VolatilePtr < [ T ] , Access < R , access:: NoAccess > > {
862
+ pub fn as_slice ( self ) -> VolatilePtr < ' a , [ T ] , Access < R , access:: NoAccess > > {
860
863
unsafe {
861
864
self . map ( |array| {
862
865
NonNull :: new ( ptr:: slice_from_raw_parts_mut ( array. as_ptr ( ) as * mut T , N ) ) . unwrap ( )
@@ -920,21 +923,21 @@ impl<T, R, W> VolatilePtr<'_, T, Access<R, W>>
920
923
where
921
924
T : Copy + ?Sized ,
922
925
{
923
- pub unsafe fn read_unsafe ( & self ) -> T
926
+ pub unsafe fn read_unsafe ( self ) -> T
924
927
where
925
928
R : access:: Unsafe ,
926
929
{
927
930
unsafe { ptr:: read_volatile ( self . pointer . as_ptr ( ) ) }
928
931
}
929
932
930
- pub unsafe fn write_unsafe ( & mut self , value : T )
933
+ pub unsafe fn write_unsafe ( self , value : T )
931
934
where
932
935
W : access:: Unsafe ,
933
936
{
934
937
unsafe { ptr:: write_volatile ( self . pointer . as_ptr ( ) , value) } ;
935
938
}
936
939
937
- pub unsafe fn update_unsafe < F > ( & mut self , f : F )
940
+ pub unsafe fn update_unsafe < F > ( self , f : F )
938
941
where
939
942
R : access:: Unsafe ,
940
943
W : access:: Unsafe ,
@@ -946,6 +949,17 @@ where
946
949
}
947
950
}
948
951
952
+ impl < ' a , T , A > Clone for VolatilePtr < ' a , T , A >
953
+ where
954
+ T : ?Sized ,
955
+ {
956
+ fn clone ( & self ) -> Self {
957
+ * self
958
+ }
959
+ }
960
+
961
+ impl < ' a , T , A > Copy for VolatilePtr < ' a , T , A > where T : ?Sized { }
962
+
949
963
impl < T , W > fmt:: Debug for VolatilePtr < ' _ , T , Access < access:: SafeAccess , W > >
950
964
where
951
965
T : Copy + fmt:: Debug + ?Sized ,
0 commit comments