Skip to content

Commit 9894588

Browse files
committed
Remove the const_generics feature flag
Currently, the "unstable" feature no longer compiles on recent nightly Rust toolchains, because it enables the `const_generics` feature flag. Since const generics have stabilized, this feature flag is no longer necessary, and results in a compilation error on recent toolchains. This commit removes `#[feature(const_generics)]` from the crate. Now, the "unstable" feature builds on recent nightly compilers. Additionally, we can remove the "unstable" feature flag from the impls for converting volatile arrays to slices, as that impl no longer requires an unstable feature. In order to make the tests pass on stable Rust after removing the unstable feature flag from the impls for arrays, I had to modify the examples so that they no longer use other unstable methods, such as `copy_from_slice`. I think the new examples still get the point across, although they're maybe not quite as nice... Fixes rust-osdev#24
1 parent 831246d commit 9894588

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/lib.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
#![no_std]
99
#![cfg_attr(feature = "unstable", feature(core_intrinsics))]
10-
#![cfg_attr(feature = "unstable", feature(const_generics))]
1110
#![cfg_attr(feature = "unstable", feature(slice_range))]
1211
#![cfg_attr(feature = "unstable", allow(incomplete_features))]
1312
#![cfg_attr(all(feature = "unstable", test), feature(slice_as_chunks))]
@@ -684,10 +683,6 @@ where
684683
}
685684

686685
/// 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")]
691686
impl<R, A, T, const N: usize> Volatile<R, A>
692687
where
693688
R: Deref<Target = [T; N]>,
@@ -698,21 +693,21 @@ where
698693
///
699694
/// ## Example
700695
///
701-
/// Copying two elements from a volatile array reference using `copy_into_slice`:
696+
/// Reading a subslice from a volatile array reference using `index`:
702697
///
703698
/// ```
704699
/// use volatile::Volatile;
705700
///
706-
/// let src = [1, 2];
701+
/// let src = [1, 2, 3, 4];
707702
/// let volatile = Volatile::new(&src);
708-
/// let mut dst = [0, 0];
709703
///
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
711705
/// let volatile_slice = volatile.as_slice();
712706
/// // we can now use the slice methods
713-
/// volatile_slice.copy_into_slice(&mut dst);
707+
/// let subslice = volatile_slice.index(2..);
714708
///
715-
/// assert_eq!(dst, [1, 2]);
709+
/// assert_eq!(subslice.index(0).read(), 3);
710+
/// assert_eq!(subslice.index(1).read(), 4);
716711
/// ```
717712
pub fn as_slice(&self) -> Volatile<&[T], A> {
718713
self.map(|array| &array[..])
@@ -724,21 +719,20 @@ where
724719
///
725720
/// ## Example
726721
///
727-
/// Copying two elements from a slice into a mutable array reference:
722+
/// Writing to an index of a mutable array reference:
728723
///
729724
/// ```
730725
/// use volatile::Volatile;
731726
///
732-
/// let src = [1, 2, 3, 4];
733727
/// let mut dst = [0, 0];
734728
/// let mut volatile = Volatile::new(&mut dst);
735729
///
736730
/// // convert the `Volatile<&mut [i32; 2]>` array reference to a `Volatile<&mut [i32]>` slice
737731
/// let mut volatile_slice = volatile.as_mut_slice();
738732
/// // we can now use the slice methods
739-
/// volatile_slice.copy_from_slice(&src[2..]);
733+
/// volatile_slice.index_mut(1).write(1);
740734
///
741-
/// assert_eq!(dst, [3, 4]);
735+
/// assert_eq!(dst, [0, 1]);
742736
/// ```
743737
pub fn as_mut_slice(&mut self) -> Volatile<&mut [T], A>
744738
where

0 commit comments

Comments
 (0)