A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://doc.rust-lang.org/std/ptr/fn.replace.html below:

replace in std::ptr - Rust

Function replace1.0.0 (const: 1.83.0) · Source
pub const unsafe fn replace<T>(dst: *mut T, src: T) -> T
Expand description

Moves src into the pointed dst, returning the previous dst value.

Neither value is dropped.

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:

Note that even if T has size 0, the pointer must be properly aligned.

§Examples
use std::ptr;

let mut rust = vec!['b', 'u', 's', 't'];

let b = unsafe {
    ptr::replace(&mut rust[0], 'r')
};

assert_eq!(b, 'b');
assert_eq!(rust, &['r', 'u', 's', 't']);

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4