]> git.lizzy.rs Git - rust.git/commitdiff
Add basic doc example for `core::ptr::write_bytes`.
authorCorey Farwell <coreyf@rwell.org>
Tue, 27 Sep 2016 03:11:47 +0000 (23:11 -0400)
committerCorey Farwell <coreyf@rwell.org>
Tue, 27 Sep 2016 03:11:47 +0000 (23:11 -0400)
src/libcore/intrinsics.rs

index 22abe7a99b1870890bbfad80068066594147ab02..6c4da2a88510d20865a4fb3023a62617524302f9 100644 (file)
 
     /// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
     /// bytes of memory starting at `dst` to `val`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::ptr;
+    ///
+    /// let mut vec = vec![0; 4];
+    /// unsafe {
+    ///     let vec_ptr = vec.as_mut_ptr();
+    ///     ptr::write_bytes(vec_ptr, b'a', 2);
+    /// }
+    /// assert_eq!(vec, [b'a', b'a', 0, 0]);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);