@@ -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 ( & mut 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 > ( & mut 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 < ' a , F , U > ( & ' a 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 < ' a , F , U > (
395
408
& ' a 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 > ( & mut self , f : F ) -> VolatilePtr < 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 > ( & mut self , f : F ) -> VolatilePtr < 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 ( & self , index : usize ) -> VolatilePtr < T , Access < R , access:: NoAccess > > {
484
503
assert ! ( index < self . pointer. len( ) , "index out of bounds" ) ;
485
504
unsafe {
@@ -489,6 +508,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
489
508
}
490
509
}
491
510
511
+ #[ inline]
492
512
pub fn index_mut < I > (
493
513
& mut self ,
494
514
index : I ,
@@ -502,6 +522,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
502
522
}
503
523
504
524
#[ cfg( feature = "very_unstable" ) ]
525
+ #[ inline]
505
526
pub const fn index_mut_const ( & mut self , index : usize ) -> VolatilePtr < T , Access < R , W > > {
506
527
assert ! ( index < self . pointer. len( ) , "index out of bounds" ) ;
507
528
unsafe {
@@ -512,6 +533,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
512
533
}
513
534
514
535
/// Returns an iterator over the slice.
536
+ #[ inline]
515
537
pub fn iter < ' b > (
516
538
& ' b self ,
517
539
) -> impl Iterator < Item = VolatilePtr < ' b , T , Access < R , access:: NoAccess > > > + ' b {
@@ -520,6 +542,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
520
542
}
521
543
522
544
/// Returns an iterator that allows modifying each value.
545
+ #[ inline]
523
546
pub fn iter_mut < ' b > (
524
547
& ' b mut self ,
525
548
) -> impl Iterator < Item = VolatilePtr < ' b , T , Access < R , W > > > + ' b {
@@ -563,6 +586,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
563
586
/// assert_eq!(src, [1, 2]);
564
587
/// assert_eq!(dst, [5, 1, 2]);
565
588
/// ```
589
+ #[ inline]
566
590
pub fn copy_into_slice ( & self , dst : & mut [ T ] )
567
591
where
568
592
T : Copy ,
@@ -620,6 +644,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
620
644
/// assert_eq!(src, [1, 2, 3, 4]);
621
645
/// assert_eq!(dst, [3, 4]);
622
646
/// ```
647
+ #[ inline]
623
648
pub fn copy_from_slice ( & mut self , src : & [ T ] )
624
649
where
625
650
T : Copy ,
@@ -674,6 +699,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
674
699
/// volatile.copy_within(1..5, 8);
675
700
///
676
701
/// assert_eq!(&byte_array, b"Hello, Wello!");
702
+ #[ inline]
677
703
pub fn copy_within ( & mut self , src : impl RangeBounds < usize > , dest : usize )
678
704
where
679
705
T : Copy ,
@@ -699,6 +725,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
699
725
}
700
726
}
701
727
728
+ #[ inline]
702
729
pub fn split_at (
703
730
& self ,
704
731
mid : usize ,
@@ -712,6 +739,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
712
739
unsafe { self . split_at_unchecked ( mid) }
713
740
}
714
741
742
+ #[ inline]
715
743
pub fn split_at_mut (
716
744
& mut self ,
717
745
mid : usize ,
@@ -725,6 +753,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
725
753
unsafe { self . split_at_mut_unchecked ( mid) }
726
754
}
727
755
756
+ #[ inline]
728
757
unsafe fn split_at_unchecked (
729
758
& self ,
730
759
mid : usize ,
@@ -741,6 +770,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
741
770
}
742
771
}
743
772
773
+ #[ inline]
744
774
unsafe fn split_at_mut_unchecked (
745
775
& mut self ,
746
776
mid : usize ,
@@ -767,6 +797,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
767
797
}
768
798
}
769
799
800
+ #[ inline]
770
801
pub fn as_chunks < const N : usize > (
771
802
& self ,
772
803
) -> (
@@ -782,6 +813,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
782
813
( array_slice, remainder)
783
814
}
784
815
816
+ #[ inline]
785
817
pub unsafe fn as_chunks_unchecked < const N : usize > (
786
818
& self ,
787
819
) -> VolatilePtr < [ [ T ; N ] ] , Access < R , access:: NoAccess > > {
@@ -800,6 +832,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
800
832
unsafe { VolatilePtr :: new_generic ( pointer) }
801
833
}
802
834
835
+ #[ inline]
803
836
pub fn as_chunks_mut < const N : usize > (
804
837
& mut self ,
805
838
) -> (
@@ -815,6 +848,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
815
848
( array_slice, remainder)
816
849
}
817
850
851
+ #[ inline]
818
852
pub unsafe fn as_chunks_unchecked_mut < const N : usize > (
819
853
& mut self ,
820
854
) -> VolatilePtr < [ [ T ; N ] ] , Access < R , W > > {
@@ -833,6 +867,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
833
867
unsafe { VolatilePtr :: new_generic ( pointer) }
834
868
}
835
869
870
+ #[ inline]
836
871
pub unsafe fn as_chunks_unchecked_by_val < const N : usize > (
837
872
self ,
838
873
) -> VolatilePtr < ' a , [ [ T ; N ] ] , Access < R , W > > {
@@ -876,6 +911,7 @@ impl<R, W> VolatilePtr<'_, [u8], Access<R, W>> {
876
911
/// buf.fill(1);
877
912
/// assert_eq!(unsafe { buf.as_ptr().as_mut() }, &mut vec![1; 10]);
878
913
/// ```
914
+ #[ inline]
879
915
pub fn fill ( & mut self , value : u8 )
880
916
where
881
917
W : access:: Safe ,
@@ -916,6 +952,7 @@ impl<T, R, W, const N: usize> VolatilePtr<'_, [T; N], Access<R, W>> {
916
952
///
917
953
/// assert_eq!(dst, [1, 2]);
918
954
/// ```
955
+ #[ inline]
919
956
pub fn as_slice ( & self ) -> VolatilePtr < [ T ] , Access < R , access:: NoAccess > > {
920
957
unsafe {
921
958
self . map ( |array| {
@@ -948,6 +985,7 @@ impl<T, R, W, const N: usize> VolatilePtr<'_, [T; N], Access<R, W>> {
948
985
///
949
986
/// assert_eq!(dst, [1, 2]);
950
987
/// ```
988
+ #[ inline]
951
989
pub fn as_slice_mut < ' a > ( & ' a mut self ) -> VolatilePtr < ' a , [ T ] , Access < R , W > > {
952
990
unsafe {
953
991
self . map_mut ( |array| {
@@ -978,6 +1016,7 @@ where
978
1016
/// assert_eq!(read_only.read(), -4);
979
1017
/// // read_only.write(10); // compile-time error
980
1018
/// ```
1019
+ #[ inline]
981
1020
pub fn read_only ( self ) -> VolatilePtr < ' a , T , Access < R , access:: NoAccess > > {
982
1021
unsafe { VolatilePtr :: new_generic ( self . pointer ) }
983
1022
}
@@ -1002,6 +1041,7 @@ where
1002
1041
/// field_2.write(14);
1003
1042
/// // field_2.read(); // compile-time error
1004
1043
/// ```
1044
+ #[ inline]
1005
1045
pub fn write_only ( self ) -> VolatilePtr < ' a , T , Access < access:: NoAccess , W > > {
1006
1046
unsafe { VolatilePtr :: new_generic ( self . pointer ) }
1007
1047
}
@@ -1012,20 +1052,23 @@ impl<T, R, W> VolatilePtr<'_, T, Access<R, W>>
1012
1052
where
1013
1053
T : Copy + ?Sized ,
1014
1054
{
1055
+ #[ inline]
1015
1056
pub unsafe fn read_unsafe ( & self ) -> T
1016
1057
where
1017
1058
R : access:: Unsafe ,
1018
1059
{
1019
1060
unsafe { ptr:: read_volatile ( self . pointer . as_ptr ( ) ) }
1020
1061
}
1021
1062
1063
+ #[ inline]
1022
1064
pub unsafe fn write_unsafe ( & mut self , value : T )
1023
1065
where
1024
1066
W : access:: Unsafe ,
1025
1067
{
1026
1068
unsafe { ptr:: write_volatile ( self . pointer . as_ptr ( ) , value) } ;
1027
1069
}
1028
1070
1071
+ #[ inline]
1029
1072
pub unsafe fn update_unsafe < F > ( & mut self , f : F )
1030
1073
where
1031
1074
R : access:: Unsafe ,
0 commit comments