Skip to content

Commit 1515a95

Browse files
committed
Document copy_into_slice method
1 parent 53894a3 commit 1515a95

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/lib.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,38 @@ where
189189
}
190190
}
191191

192+
/// Copies all elements from `self` into `dst`, using a volatile memcpy.
193+
///
194+
/// The length of `dst` must be the same as `self`.
195+
///
196+
/// The method is only available with the `nightly` feature enabled (requires a nightly
197+
/// Rust compiler).
198+
///
199+
/// ## Panics
200+
///
201+
/// This function will panic if the two slices have different lengths.
202+
///
203+
/// ## Examples
204+
///
205+
/// Copying two elements from a volatile slice:
206+
///
207+
/// ```
208+
/// use volatile::Volatile;
209+
///
210+
/// let src = [1, 2];
211+
/// // the `Volatile` type does not work with arrays, so convert `src` to a slice
212+
/// let slice = &src[..];
213+
/// let volatile = Volatile::new(slice);
214+
/// let mut dst = [5, 0, 0];
215+
///
216+
/// // Because the slices have to be the same length,
217+
/// // we slice the destination slice from three elements
218+
/// // to two. It will panic if we don't do this.
219+
/// volatile.copy_into_slice(&mut dst[1..]);
220+
///
221+
/// assert_eq!(src, [1, 2]);
222+
/// assert_eq!(dst, [5, 1, 2]);
223+
/// ```
192224
#[cfg(feature = "nightly")]
193225
pub fn copy_into_slice(&self, dst: &mut [T])
194226
where
@@ -212,13 +244,16 @@ where
212244
///
213245
/// The length of `src` must be the same as `self`.
214246
///
247+
/// The method is only available with the `nightly` feature enabled (requires a nightly
248+
/// Rust compiler).
249+
///
215250
/// ## Panics
216251
///
217252
/// This function will panic if the two slices have different lengths.
218253
///
219254
/// ## Examples
220255
///
221-
/// Copying two elements from a slice into another:
256+
/// Copying two elements from a slice into a volatile slice:
222257
///
223258
/// ```
224259
/// use volatile::Volatile;

0 commit comments

Comments
 (0)