本文簡要介紹rust語言中 core::ptr::NonNull.dangling
的用法。
用法
pub const fn dangling() -> Self
創建一個新的 NonNull
,它是懸空的,但 well-aligned。
這對於初始化延遲分配的類型很有用,例如 Vec::new
。
請注意,指針值可能表示指向 T
的有效指針,這意味著不能將其用作 “not yet initialized” 標記值。延遲分配的類型必須通過其他方式跟蹤初始化。
例子
use std::ptr::NonNull;
let ptr = NonNull::<u32>::dangling();
// Important: don't try to access the value of `ptr` without
// initializing it first! The pointer is not null but isn't valid either!
相關用法
- Rust NonNull.dangling用法及代碼示例
- Rust NonNull.len用法及代碼示例
- Rust NonNull.as_uninit_slice_mut用法及代碼示例
- Rust NonNull.slice_from_raw_parts用法及代碼示例
- Rust NonNull.as_mut_ptr用法及代碼示例
- Rust NonNull.as_mut用法及代碼示例
- Rust NonNull.cast用法及代碼示例
- Rust NonNull.as_ptr用法及代碼示例
- Rust NonNull.new_unchecked用法及代碼示例
- Rust NonNull.get_unchecked_mut用法及代碼示例
- Rust NonNull.new用法及代碼示例
- Rust NonNull.as_non_null_ptr用法及代碼示例
- Rust NonNull.as_ref用法及代碼示例
- Rust NonZeroU128.checked_pow用法及代碼示例
- Rust NonZeroUsize.checked_next_power_of_two用法及代碼示例
- Rust NonZeroI128.saturating_pow用法及代碼示例
- Rust NonZeroI64.wrapping_abs用法及代碼示例
- Rust NonZeroU64.checked_mul用法及代碼示例
- Rust NonZeroU16.saturating_pow用法及代碼示例
- Rust NonZeroU8.checked_add用法及代碼示例
- Rust NonZeroUsize.checked_pow用法及代碼示例
- Rust NonZeroU8.unchecked_add用法及代碼示例
- Rust NonZeroUsize.leading_zeros用法及代碼示例
- Rust NonZeroI32.trailing_zeros用法及代碼示例
- Rust NonZeroI8.saturating_pow用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 core::ptr::NonNull.dangling。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。