@@ -145,14 +145,17 @@ impl<T> VolatilePtr<'_, T>
145
145
where
146
146
T : ?Sized ,
147
147
{
148
+ #[ inline]
148
149
pub unsafe fn new_read_write ( pointer : NonNull < T > ) -> VolatilePtr < ' static , T > {
149
150
unsafe { VolatilePtr :: new_with_access ( pointer, Access :: read_write ( ) ) }
150
151
}
151
152
153
+ #[ inline]
152
154
pub const unsafe fn new_read_only ( pointer : NonNull < T > ) -> VolatilePtr < ' static , T , ReadOnly > {
153
155
unsafe { VolatilePtr :: new_with_access ( pointer, Access :: read_only ( ) ) }
154
156
}
155
157
158
+ #[ inline]
156
159
pub const unsafe fn new_write_only ( pointer : NonNull < T > ) -> VolatilePtr < ' static , T , WriteOnly > {
157
160
unsafe { VolatilePtr :: new_with_access ( pointer, Access :: write_only ( ) ) }
158
161
}
@@ -180,6 +183,7 @@ where
180
183
/// volatile.write(1);
181
184
/// assert_eq!(volatile.read(), 1);
182
185
/// ```
186
+ #[ inline]
183
187
pub const unsafe fn new_with_access < A > (
184
188
pointer : NonNull < T > ,
185
189
access : A ,
@@ -188,6 +192,7 @@ where
188
192
unsafe { Self :: new_generic ( pointer) }
189
193
}
190
194
195
+ #[ inline]
191
196
pub const unsafe fn new_generic < ' a , A > ( pointer : NonNull < T > ) -> VolatilePtr < ' a , T , A > {
192
197
VolatilePtr {
193
198
pointer,
@@ -196,13 +201,15 @@ where
196
201
}
197
202
}
198
203
204
+ #[ inline]
199
205
pub fn from_ref < ' a > ( reference : & ' a T ) -> VolatilePtr < ' a , T , ReadOnly >
200
206
where
201
207
T : ' a ,
202
208
{
203
209
unsafe { VolatilePtr :: new_generic ( reference. into ( ) ) }
204
210
}
205
211
212
+ #[ inline]
206
213
pub fn from_mut_ref < ' a > ( reference : & ' a mut T ) -> VolatilePtr < ' a , T >
207
214
where
208
215
T : ' a ,
@@ -238,6 +245,7 @@ where
238
245
/// let mut_reference = unsafe { VolatilePtr::new_read_write(NonNull::from(&mut value)) };
239
246
/// assert_eq!(mut_reference.read(), 50);
240
247
/// ```
248
+ #[ inline]
241
249
pub fn read ( self ) -> T
242
250
where
243
251
R : access:: Safe ,
@@ -265,6 +273,7 @@ where
265
273
///
266
274
/// assert_eq!(volatile.read(), 50);
267
275
/// ```
276
+ #[ inline]
268
277
pub fn write ( self , value : T )
269
278
where
270
279
W : access:: Safe ,
@@ -290,6 +299,7 @@ where
290
299
///
291
300
/// assert_eq!(volatile.read(), 43);
292
301
/// ```
302
+ #[ inline]
293
303
pub fn update < F > ( self , f : F )
294
304
where
295
305
R : access:: Safe ,
@@ -331,6 +341,7 @@ where
331
341
///
332
342
/// assert_eq!(unsafe { *unwrapped }, 50); // non volatile access, be careful!
333
343
/// ```
344
+ #[ inline]
334
345
pub fn as_ptr ( self ) -> NonNull < T > {
335
346
self . pointer
336
347
}
@@ -382,6 +393,7 @@ where
382
393
/// value
383
394
/// })};
384
395
/// ```
396
+ #[ inline]
385
397
pub unsafe fn map < F , U > ( self , f : F ) -> VolatilePtr < ' a , U , Access < R , access:: NoAccess > >
386
398
where
387
399
F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
@@ -391,6 +403,7 @@ where
391
403
}
392
404
393
405
#[ cfg( feature = "very_unstable" ) ]
406
+ #[ inline]
394
407
pub const unsafe fn map_const < F , U > (
395
408
self ,
396
409
f : F ,
@@ -402,6 +415,7 @@ where
402
415
unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
403
416
}
404
417
418
+ #[ inline]
405
419
pub unsafe fn map_mut < F , U > ( self , f : F ) -> VolatilePtr < ' a , U , Access < R , W > >
406
420
where
407
421
F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
@@ -411,6 +425,7 @@ where
411
425
}
412
426
413
427
#[ cfg( feature = "very_unstable" ) ]
428
+ #[ inline]
414
429
pub const unsafe fn map_mut_const < F , U > ( self , f : F ) -> VolatilePtr < ' a , U , Access < R , W > >
415
430
where
416
431
F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
@@ -423,10 +438,12 @@ where
423
438
/// Methods for volatile slices
424
439
#[ cfg( feature = "unstable" ) ]
425
440
impl < ' a , T , R , W > VolatilePtr < ' a , [ T ] , Access < R , W > > {
441
+ #[ inline]
426
442
pub fn len ( self ) -> usize {
427
443
self . pointer . len ( )
428
444
}
429
445
446
+ #[ inline]
430
447
pub fn is_empty ( & self ) -> bool {
431
448
self . pointer . len ( ) == 0
432
449
}
@@ -467,6 +484,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
467
484
/// let subslice = volatile.index(1..);
468
485
/// assert_eq!(subslice.index(0).read(), 2);
469
486
/// ```
487
+ #[ inline]
470
488
pub fn index < I > (
471
489
self ,
472
490
index : I ,
@@ -480,6 +498,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
480
498
}
481
499
482
500
#[ cfg( feature = "very_unstable" ) ]
501
+ #[ inline]
483
502
pub const fn index_const (
484
503
self ,
485
504
index : usize ,
@@ -492,6 +511,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
492
511
}
493
512
}
494
513
514
+ #[ inline]
495
515
pub fn index_mut < I > (
496
516
self ,
497
517
index : I ,
@@ -505,6 +525,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
505
525
}
506
526
507
527
#[ cfg( feature = "very_unstable" ) ]
528
+ #[ inline]
508
529
pub const fn index_mut_const ( self , index : usize ) -> VolatilePtr < ' a , T , Access < R , W > > {
509
530
assert ! ( index < self . pointer. len( ) , "index out of bounds" ) ;
510
531
unsafe {
@@ -515,6 +536,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
515
536
}
516
537
517
538
/// Returns an iterator over the slice.
539
+ #[ inline]
518
540
pub fn iter < ' b > (
519
541
self ,
520
542
) -> impl Iterator < Item = VolatilePtr < ' a , T , Access < R , access:: NoAccess > > > + ' b
@@ -528,6 +550,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
528
550
}
529
551
530
552
/// Returns an iterator that allows modifying each value.
553
+ #[ inline]
531
554
pub fn iter_mut < ' b > ( self ) -> impl Iterator < Item = VolatilePtr < ' a , T , Access < R , W > > > + ' b
532
555
where
533
556
' a : ' b ,
@@ -572,6 +595,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
572
595
/// assert_eq!(src, [1, 2]);
573
596
/// assert_eq!(dst, [5, 1, 2]);
574
597
/// ```
598
+ #[ inline]
575
599
pub fn copy_into_slice ( self , dst : & mut [ T ] )
576
600
where
577
601
T : Copy ,
@@ -629,6 +653,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
629
653
/// assert_eq!(src, [1, 2, 3, 4]);
630
654
/// assert_eq!(dst, [3, 4]);
631
655
/// ```
656
+ #[ inline]
632
657
pub fn copy_from_slice ( self , src : & [ T ] )
633
658
where
634
659
T : Copy ,
@@ -683,6 +708,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
683
708
/// volatile.copy_within(1..5, 8);
684
709
///
685
710
/// assert_eq!(&byte_array, b"Hello, Wello!");
711
+ #[ inline]
686
712
pub fn copy_within ( self , src : impl RangeBounds < usize > , dest : usize )
687
713
where
688
714
T : Copy ,
@@ -708,6 +734,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
708
734
}
709
735
}
710
736
737
+ #[ inline]
711
738
pub fn split_at (
712
739
self ,
713
740
mid : usize ,
@@ -721,6 +748,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
721
748
unsafe { self . split_at_unchecked ( mid) }
722
749
}
723
750
751
+ #[ inline]
724
752
pub fn split_at_mut (
725
753
self ,
726
754
mid : usize ,
@@ -734,6 +762,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
734
762
unsafe { self . split_at_mut_unchecked ( mid) }
735
763
}
736
764
765
+ #[ inline]
737
766
unsafe fn split_at_unchecked (
738
767
self ,
739
768
mid : usize ,
@@ -750,6 +779,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
750
779
}
751
780
}
752
781
782
+ #[ inline]
753
783
unsafe fn split_at_mut_unchecked (
754
784
self ,
755
785
mid : usize ,
@@ -776,6 +806,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
776
806
}
777
807
}
778
808
809
+ #[ inline]
779
810
pub fn as_chunks < const N : usize > (
780
811
self ,
781
812
) -> (
@@ -791,6 +822,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
791
822
( array_slice, remainder)
792
823
}
793
824
825
+ #[ inline]
794
826
pub unsafe fn as_chunks_unchecked < const N : usize > (
795
827
self ,
796
828
) -> VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , access:: NoAccess > > {
@@ -809,6 +841,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
809
841
unsafe { VolatilePtr :: new_generic ( pointer) }
810
842
}
811
843
844
+ #[ inline]
812
845
pub fn as_chunks_mut < const N : usize > (
813
846
self ,
814
847
) -> (
@@ -824,6 +857,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
824
857
( array_slice, remainder)
825
858
}
826
859
860
+ #[ inline]
827
861
pub unsafe fn as_chunks_unchecked_mut < const N : usize > (
828
862
self ,
829
863
) -> VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , W > > {
@@ -842,6 +876,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
842
876
unsafe { VolatilePtr :: new_generic ( pointer) }
843
877
}
844
878
879
+ #[ inline]
845
880
pub unsafe fn as_chunks_unchecked_by_val < const N : usize > (
846
881
self ,
847
882
) -> VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , W > > {
@@ -885,6 +920,7 @@ impl<R, W> VolatilePtr<'_, [u8], Access<R, W>> {
885
920
/// buf.fill(1);
886
921
/// assert_eq!(unsafe { buf.as_ptr().as_mut() }, &mut vec![1; 10]);
887
922
/// ```
923
+ #[ inline]
888
924
pub fn fill ( self , value : u8 )
889
925
where
890
926
W : access:: Safe ,
@@ -925,6 +961,7 @@ impl<'a, T, R, W, const N: usize> VolatilePtr<'a, [T; N], Access<R, W>> {
925
961
///
926
962
/// assert_eq!(dst, [1, 2]);
927
963
/// ```
964
+ #[ inline]
928
965
pub fn as_slice ( self ) -> VolatilePtr < ' a , [ T ] , Access < R , access:: NoAccess > > {
929
966
unsafe {
930
967
self . map ( |array| {
@@ -957,6 +994,7 @@ impl<'a, T, R, W, const N: usize> VolatilePtr<'a, [T; N], Access<R, W>> {
957
994
///
958
995
/// assert_eq!(dst, [1, 2]);
959
996
/// ```
997
+ #[ inline]
960
998
pub fn as_slice_mut ( self ) -> VolatilePtr < ' a , [ T ] , Access < R , W > > {
961
999
unsafe {
962
1000
self . map_mut ( |array| {
@@ -987,6 +1025,7 @@ where
987
1025
/// assert_eq!(read_only.read(), -4);
988
1026
/// // read_only.write(10); // compile-time error
989
1027
/// ```
1028
+ #[ inline]
990
1029
pub fn read_only ( self ) -> VolatilePtr < ' a , T , Access < R , access:: NoAccess > > {
991
1030
unsafe { VolatilePtr :: new_generic ( self . pointer ) }
992
1031
}
@@ -1011,6 +1050,7 @@ where
1011
1050
/// field_2.write(14);
1012
1051
/// // field_2.read(); // compile-time error
1013
1052
/// ```
1053
+ #[ inline]
1014
1054
pub fn write_only ( self ) -> VolatilePtr < ' a , T , Access < access:: NoAccess , W > > {
1015
1055
unsafe { VolatilePtr :: new_generic ( self . pointer ) }
1016
1056
}
@@ -1021,20 +1061,23 @@ impl<T, R, W> VolatilePtr<'_, T, Access<R, W>>
1021
1061
where
1022
1062
T : Copy + ?Sized ,
1023
1063
{
1064
+ #[ inline]
1024
1065
pub unsafe fn read_unsafe ( self ) -> T
1025
1066
where
1026
1067
R : access:: Unsafe ,
1027
1068
{
1028
1069
unsafe { ptr:: read_volatile ( self . pointer . as_ptr ( ) ) }
1029
1070
}
1030
1071
1072
+ #[ inline]
1031
1073
pub unsafe fn write_unsafe ( self , value : T )
1032
1074
where
1033
1075
W : access:: Unsafe ,
1034
1076
{
1035
1077
unsafe { ptr:: write_volatile ( self . pointer . as_ptr ( ) , value) } ;
1036
1078
}
1037
1079
1080
+ #[ inline]
1038
1081
pub unsafe fn update_unsafe < F > ( self , f : F )
1039
1082
where
1040
1083
R : access:: Unsafe ,
@@ -1051,6 +1094,7 @@ impl<'a, T, A> Clone for VolatilePtr<'a, T, A>
1051
1094
where
1052
1095
T : ?Sized ,
1053
1096
{
1097
+ #[ inline]
1054
1098
fn clone ( & self ) -> Self {
1055
1099
* self
1056
1100
}
0 commit comments