Skip to content

Commit a4ccd3d

Browse files
committed
Document new slice methods
1 parent 401c5ba commit a4ccd3d

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

src/lib.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ where
482482
///
483483
/// The length of `dst` must be the same as `self`.
484484
///
485-
/// The method is only available with the `nightly` feature enabled (requires a nightly
485+
/// The method is only available with the `unstable` feature enabled (requires a nightly
486486
/// Rust compiler).
487487
///
488488
/// ## Panics
@@ -533,7 +533,10 @@ where
533533
///
534534
/// The length of `src` must be the same as `self`.
535535
///
536-
/// The method is only available with the `nightly` feature enabled (requires a nightly
536+
/// This method is similar to the `slice::copy_from_slice` method of the standard library. The
537+
/// difference is that this method performs a volatile copy.
538+
///
539+
/// The method is only available with the `unstable` feature enabled (requires a nightly
537540
/// Rust compiler).
538541
///
539542
/// ## Panics
@@ -581,6 +584,38 @@ where
581584
}
582585
}
583586

587+
/// Copies elements from one part of the slice to another part of itself, using a
588+
/// volatile `memmove`.
589+
///
590+
/// `src` is the range within `self` to copy from. `dest` is the starting index of the
591+
/// range within `self` to copy to, which will have the same length as `src`. The two ranges
592+
/// may overlap. The ends of the two ranges must be less than or equal to `self.len()`.
593+
///
594+
/// This method is similar to the `slice::copy_within` method of the standard library. The
595+
/// difference is that this method performs a volatile copy.
596+
///
597+
/// This method is only available with the `unstable` feature enabled (requires a nightly
598+
/// Rust compiler).
599+
///
600+
/// ## Panics
601+
///
602+
/// This function will panic if either range exceeds the end of the slice, or if the end
603+
/// of `src` is before the start.
604+
///
605+
/// ## Examples
606+
///
607+
/// Copying four bytes within a slice:
608+
///
609+
/// ```
610+
/// use volatile::Volatile;
611+
///
612+
/// let mut byte_array = *b"Hello, World!";
613+
/// let mut slice: &mut [u8] = &mut byte_array[..];
614+
/// let mut volatile = Volatile::new(slice);
615+
///
616+
/// volatile.copy_within(1..5, 8);
617+
///
618+
/// assert_eq!(&byte_array, b"Hello, Wello!");
584619
#[cfg(feature = "unstable")]
585620
pub fn copy_within(&mut self, src: impl RangeBounds<usize>, dest: usize)
586621
where
@@ -614,6 +649,25 @@ impl<R, A> Volatile<R, A>
614649
where
615650
R: Deref<Target = [u8]>,
616651
{
652+
/// Sets all elements of the byte slice to the given `value` using a volatile `memset`.
653+
///
654+
/// This method is similar to the `slice::fill` method of the standard library, with the
655+
/// difference that this method performs a volatile write operation. Another difference
656+
/// is that this method is only available for byte slices (not general `&mut [T]` slices)
657+
/// because there currently isn't a instrinsic function that allows non-`u8` values.
658+
///
659+
/// This method is only available with the `unstable` feature enabled (requires a nightly
660+
/// Rust compiler).
661+
///
662+
/// ## Example
663+
///
664+
/// ```rust
665+
/// use volatile::Volatile;
666+
///
667+
/// let mut buf = Volatile::new(vec![0; 10]);
668+
/// buf.fill(1);
669+
/// assert_eq!(buf.extract_inner(), vec![1; 10]);
670+
/// ```
617671
#[cfg(feature = "unstable")]
618672
pub fn fill(&mut self, value: u8)
619673
where
@@ -631,7 +685,7 @@ where
631685

632686
/// Methods for converting arrays to slices
633687
///
634-
/// These methods are only available with the `nightly` feature enabled (requires a nightly
688+
/// These methods are only available with the `unstable` feature enabled (requires a nightly
635689
/// Rust compiler).
636690
#[cfg(feature = "unstable")]
637691
impl<R, A, T, const N: usize> Volatile<R, A>

0 commit comments

Comments
 (0)