Function std::ptr::replace 1.0.0[−][src]
pub unsafe fn replace<T>(dest: *mut T, src: T) -> T
Replaces the value at dest with src, returning the old value, without
dropping either.
This function is semantically equivalent to mem::replace except that it
operates on raw pointers instead of references. When references are
available, mem::replace should be preferred.
Safety
Behavior is undefined if any of the following conditions are violated:
-
destmust point to valid, initialized memory. -
destmust be properly aligned.
Examples
use std::ptr; let mut rust = vec!['b', 'u', 's', 't']; // `mem::replace` would have the same effect without requiring the unsafe // block. let b = unsafe { ptr::replace(&mut rust[0], 'r') }; assert_eq!(b, 'b'); assert_eq!(rust, &['r', 'u', 's', 't']);Run