10
10
#![ cfg_attr( feature = "unstable" , feature( slice_range) ) ]
11
11
#![ cfg_attr( feature = "unstable" , feature( slice_ptr_get) ) ]
12
12
#![ cfg_attr( feature = "unstable" , feature( slice_ptr_len) ) ]
13
- #![ cfg_attr( feature = "unstable" , allow( incomplete_features) ) ]
13
+ #![ cfg_attr( feature = "very_unstable" , feature( const_slice_ptr_len) ) ]
14
+ #![ cfg_attr( feature = "very_unstable" , feature( const_panic) ) ]
15
+ #![ cfg_attr( feature = "very_unstable" , feature( const_fn_trait_bound) ) ]
16
+ #![ cfg_attr( feature = "very_unstable" , feature( const_fn_fn_ptr_basics) ) ]
17
+ #![ cfg_attr( feature = "very_unstable" , feature( const_trait_impl) ) ]
18
+ #![ cfg_attr( feature = "very_unstable" , feature( const_mut_refs) ) ]
19
+ #![ cfg_attr( feature = "very_unstable" , allow( incomplete_features) ) ]
14
20
#![ cfg_attr( all( feature = "unstable" , test) , feature( slice_as_chunks) ) ]
15
21
#![ warn( missing_docs) ]
16
22
#![ deny( unsafe_op_in_unsafe_fn) ]
@@ -353,13 +359,34 @@ where
353
359
unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
354
360
}
355
361
362
+ #[ cfg( feature = "very_unstable" ) ]
363
+ pub const unsafe fn map_const < ' a , F , U > (
364
+ & ' a self ,
365
+ f : F ,
366
+ ) -> VolatilePtr < ' a , U , Access < R , access:: NoAccess > >
367
+ where
368
+ F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
369
+ U : ?Sized ,
370
+ {
371
+ unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
372
+ }
373
+
356
374
pub unsafe fn map_mut < F , U > ( & mut self , f : F ) -> VolatilePtr < U , Access < R , W > >
357
375
where
358
376
F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
359
377
U : ?Sized ,
360
378
{
361
379
unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
362
380
}
381
+
382
+ #[ cfg( feature = "very_unstable" ) ]
383
+ pub const unsafe fn map_mut_const < F , U > ( & mut self , f : F ) -> VolatilePtr < U , Access < R , W > >
384
+ where
385
+ F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
386
+ U : ?Sized ,
387
+ {
388
+ unsafe { VolatilePtr :: new_generic ( f ( self . pointer ) ) }
389
+ }
363
390
}
364
391
365
392
/// Methods for volatile slices
@@ -417,6 +444,16 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
417
444
unsafe { self . map ( |slice| slice. get_unchecked_mut ( index) ) }
418
445
}
419
446
447
+ #[ cfg( feature = "very_unstable" ) ]
448
+ pub const fn index_const ( & self , index : usize ) -> VolatilePtr < T , Access < R , access:: NoAccess > > {
449
+ assert ! ( index < self . pointer. len( ) , "index out of bounds" ) ;
450
+ unsafe {
451
+ self . map_const ( |slice| {
452
+ NonNull :: new_unchecked ( slice. as_non_null_ptr ( ) . as_ptr ( ) . add ( index) )
453
+ } )
454
+ }
455
+ }
456
+
420
457
pub fn index_mut < I > (
421
458
& mut self ,
422
459
index : I ,
@@ -429,6 +466,16 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
429
466
unsafe { self . map_mut ( |slice| slice. get_unchecked_mut ( index) ) }
430
467
}
431
468
469
+ #[ cfg( feature = "very_unstable" ) ]
470
+ pub const fn index_mut_const ( & mut self , index : usize ) -> VolatilePtr < T , Access < R , W > > {
471
+ assert ! ( index < self . pointer. len( ) , "index out of bounds" ) ;
472
+ unsafe {
473
+ self . map_mut_const ( |slice| {
474
+ NonNull :: new_unchecked ( slice. as_non_null_ptr ( ) . as_ptr ( ) . add ( index) )
475
+ } )
476
+ }
477
+ }
478
+
432
479
/// Copies all elements from `self` into `dst`, using a volatile memcpy.
433
480
///
434
481
/// The length of `dst` must be the same as `self`.
0 commit comments