7
7
8
8
#![ no_std]
9
9
#![ cfg_attr( feature = "unstable" , feature( core_intrinsics) ) ]
10
- #![ cfg_attr( feature = "unstable" , feature( const_generics) ) ]
11
10
#![ cfg_attr( feature = "unstable" , feature( slice_range) ) ]
12
11
#![ cfg_attr( feature = "unstable" , allow( incomplete_features) ) ]
13
12
#![ cfg_attr( all( feature = "unstable" , test) , feature( slice_as_chunks) ) ]
@@ -684,10 +683,6 @@ where
684
683
}
685
684
686
685
/// Methods for converting arrays to slices
687
- ///
688
- /// These methods are only available with the `unstable` feature enabled (requires a nightly
689
- /// Rust compiler).
690
- #[ cfg( feature = "unstable" ) ]
691
686
impl < R , A , T , const N : usize > Volatile < R , A >
692
687
where
693
688
R : Deref < Target = [ T ; N ] > ,
@@ -698,21 +693,21 @@ where
698
693
///
699
694
/// ## Example
700
695
///
701
- /// Copying two elements from a volatile array reference using `copy_into_slice `:
696
+ /// Reading a subslice from a volatile array reference using `index `:
702
697
///
703
698
/// ```
704
699
/// use volatile::Volatile;
705
700
///
706
- /// let src = [1, 2];
701
+ /// let src = [1, 2, 3, 4 ];
707
702
/// let volatile = Volatile::new(&src);
708
- /// let mut dst = [0, 0];
709
703
///
710
- /// // convert the `Volatile<&[i32; 2 ]>` array reference to a `Volatile<&[i32]>` slice
704
+ /// // convert the `Volatile<&[i32; 4 ]>` array reference to a `Volatile<&[i32]>` slice
711
705
/// let volatile_slice = volatile.as_slice();
712
706
/// // we can now use the slice methods
713
- /// volatile_slice.copy_into_slice(&mut dst );
707
+ /// let subslice = volatile_slice.index(2.. );
714
708
///
715
- /// assert_eq!(dst, [1, 2]);
709
+ /// assert_eq!(subslice.index(0).read(), 3);
710
+ /// assert_eq!(subslice.index(1).read(), 4);
716
711
/// ```
717
712
pub fn as_slice ( & self ) -> Volatile < & [ T ] , A > {
718
713
self . map ( |array| & array[ ..] )
@@ -724,21 +719,20 @@ where
724
719
///
725
720
/// ## Example
726
721
///
727
- /// Copying two elements from a slice into a mutable array reference:
722
+ /// Writing to an index of a mutable array reference:
728
723
///
729
724
/// ```
730
725
/// use volatile::Volatile;
731
726
///
732
- /// let src = [1, 2, 3, 4];
733
727
/// let mut dst = [0, 0];
734
728
/// let mut volatile = Volatile::new(&mut dst);
735
729
///
736
730
/// // convert the `Volatile<&mut [i32; 2]>` array reference to a `Volatile<&mut [i32]>` slice
737
731
/// let mut volatile_slice = volatile.as_mut_slice();
738
732
/// // we can now use the slice methods
739
- /// volatile_slice.copy_from_slice(&src[2..] );
733
+ /// volatile_slice.index_mut(1).write(1 );
740
734
///
741
- /// assert_eq!(dst, [3, 4 ]);
735
+ /// assert_eq!(dst, [0, 1 ]);
742
736
/// ```
743
737
pub fn as_mut_slice ( & mut self ) -> Volatile < & mut [ T ] , A >
744
738
where
0 commit comments