Skip to content

Commit 2ba02a7

Browse files
committed
Add basic doc example for core::ptr::write_bytes.
1 parent 388c3f2 commit 2ba02a7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libcore/intrinsics.rs

+13
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,19 @@ extern "rust-intrinsic" {
596596

597597
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
598598
/// bytes of memory starting at `dst` to `val`.
599+
///
600+
/// # Examples
601+
///
602+
/// ```
603+
/// use std::ptr;
604+
///
605+
/// let mut vec = vec![0; 4];
606+
/// unsafe {
607+
/// let vec_ptr = vec.as_mut_ptr();
608+
/// ptr::write_bytes(vec_ptr, b'a', 2);
609+
/// }
610+
/// assert_eq!(vec, [b'a', b'a', 0, 0]);
611+
/// ```
599612
#[stable(feature = "rust1", since = "1.0.0")]
600613
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
601614

0 commit comments

Comments
 (0)