Function write_bytes
unsafe const fn write_bytes<T>(dst: *mut T, val: u8, count: usize)
Sets count * size_of::<T>() bytes of memory starting at dst to
val.
write_bytes is similar to C's memset, but sets count * size_of::<T>() bytes to val.
Safety
Behavior is undefined if any of the following conditions are violated:
-
dstmust be valid for writes ofcount * size_of::<T>()bytes. -
dstmust be properly aligned.
Note that even if the effectively copied size (count * size_of::<T>()) is
0, the pointer must be properly aligned.
Additionally, note that changing *dst in this way can easily lead to undefined behavior (UB)
later if the written bytes are not a valid representation of some T. For instance, the
following is an incorrect use of this function:
unsafe
Examples
Basic usage:
use ptr;
let mut vec = vec!;
unsafe
assert_eq!;