pub struct Ptr;
Implementations§
Source§impl Ptr
§Safe methods
impl Ptr
§Safe methods
Sourcepub const LITTLE_ENDIAN: bool = true
pub const LITTLE_ENDIAN: bool = true
True if the system’s architecture is little-endian.
Sourcepub const BIG_ENDIAN: bool = false
pub const BIG_ENDIAN: bool = false
True if the system’s architecture is big-endian.
Sourcepub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool
pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool
Compares raw pointer addresses for equality, ignoring any metadata in fat pointers.
See core::ptr::
addr_eq
.
For functions you can use core::ptr::
fn_addr_eq
directly.
Sourcepub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool
pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool
Compares raw pointers for equality.
See core::ptr::
eq
.
Sourcepub const fn dangling<T>() -> *const T
pub const fn dangling<T>() -> *const T
Creates a new pointer that is dangling, but non-null and well-aligned.
See core::ptr::
dangling
.
Sourcepub const fn dangling_mut<T>() -> *mut T
pub const fn dangling_mut<T>() -> *mut T
Creates a new pointer that is dangling, but non-null and well-aligned.
See core::ptr::
dangling_mut
.
Sourcepub fn in_stack<T>(address: *const T, stack_size: usize) -> bool
pub fn in_stack<T>(address: *const T, stack_size: usize) -> bool
Returns true
if it’s probable the given address
is in the stack, for a
given stack_size
.
§Stack size
The default stack size is platform-dependent and subject to change. Currently, it is 2 MiB on all Tier-1 platforms. Note that the stack size of the main thread is not determined by Rust.
If the address is close to a stack variable address it might be stack allocated.
§Example
const STACK_SIZE: usize = 2 << 20; // assume a 2 MB stack size
let in_stack: [i32; 10] = [0; 10];
let in_heap = vec![0; 10];
assert_eq!(true, Ptr::in_stack(in_stack.as_ptr(), STACK_SIZE));
assert_eq!(false, Ptr::in_stack(in_heap.as_ptr(), STACK_SIZE));
Sourcepub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T
pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T
Convert an exclusive reference to a raw pointer.
See core::ptr::
from_mut
.
Sourcepub const fn from_ref<T: ?Sized>(r: &T) -> *const T
pub const fn from_ref<T: ?Sized>(r: &T) -> *const T
Convert a shared reference to a raw pointer.
See core::ptr::
from_ref
.
Sourcepub fn hash<T: ?Sized, S: Hasher>(hashee: *const T, into: &mut S)
pub fn hash<T: ?Sized, S: Hasher>(hashee: *const T, into: &mut S)
Hash a raw pointer.
See core::ptr::
hash
.
Sourcepub const fn null_mut<T>() -> *mut T
pub const fn null_mut<T>() -> *mut T
Creates a null mutable raw pointer.
See core::ptr::
null_mut
.
Sourcepub const fn size_ratio(other_size: usize) -> [usize; 2]
pub const fn size_ratio(other_size: usize) -> [usize; 2]
Returns the ratio of a usize
in respect to other_size
.
For example: the ratio will be (1, 1)
if both sizes are equal, (2, 1)
if the pointer size is double the other size, and (1, 2)
if is is half
the other byte size.
§Examples
use devela::Ptr;
assert_eq![Ptr::size_ratio(0), [1, 0]];
assert_eq![Ptr::size_ratio(size_of::<usize>()), [1, 1]];
assert_eq![Ptr::size_ratio(size_of::<&str>()), [1, 2]];
assert_eq![Ptr::size_ratio(size_of::<String>()), [1, 3]];
#[cfg(target_pointer_width = "64")]
assert_eq![Ptr::size_ratio(size_of::<char>()), [2,1]];
Note that when other_size == 0
it returns (1, 0)
which is an invalid ratio.
Sourcepub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T]
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T]
Forms a raw slice from a pointer and a length.
See core::ptr::
slice_from_raw_parts
, and also
Slice::
from_raw_parts
.
Sourcepub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T]
pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T]
Forms a mutable raw slice from a mutable pointer and a length.
See core::ptr::
slice_from_raw_parts_mut
, and also
Slice::
from_raw_parts_mut
.
Sourcepub fn with_exposed_provenance<T>(addr: usize) -> *const T
pub fn with_exposed_provenance<T>(addr: usize) -> *const T
Converts an address back to a pointer, picking up some previously ‘exposed’ provenance.
See core::ptr::
with_exposed_provenance
and <ptr>::
expose_provenance
.
Sourcepub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T
pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T
Converts an address back to a mutable pointer, picking up some previously ‘exposed’ provenance.
See core::ptr::
with_exposed_provenance_mut
and <ptr>::
expose_provenance
.
Sourcepub fn without_provenance<T>(addr: usize) -> *const T
pub fn without_provenance<T>(addr: usize) -> *const T
Creates a pointer with the given address and no provenance.
See core::ptr::
without_provenance
<ptr>::
with_addr
,
and <ptr>::
map_addr
.
Sourcepub fn without_provenance_mut<T>(addr: usize) -> *mut T
pub fn without_provenance_mut<T>(addr: usize) -> *mut T
Creates a pointer with the given address and no provenance.
See core::ptr::
without_provenance_mut
<ptr>::
with_addr
,
and <ptr>::
map_addr
.
Source§impl Ptr
impl Ptr
Sourcepub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize)
Available on unsafe··
only.
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize)
unsafe··
only.Copies count * size_of::<T>()
bytes from src
to dst
. Must not overlap.
§Safety
See core::ptr::
copy_nonoverlapping
.
Sourcepub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T)
Available on unsafe··
only.
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T)
unsafe··
only.Sourcepub const unsafe fn read_unaligned<T>(src: *const T) -> T
Available on unsafe··
only.
pub const unsafe fn read_unaligned<T>(src: *const T) -> T
unsafe··
only.Sourcepub unsafe fn read_volatile<T>(src: *const T) -> T
Available on unsafe··
only.
pub unsafe fn read_volatile<T>(src: *const T) -> T
unsafe··
only.Performs a volatile read of the value from src without moving it.
§Safety
See core::ptr::
read_volatile
.
Sourcepub unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize)
Available on unsafe··
only.
pub unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize)
unsafe··
only.Swaps the two regions of memory beginning at x
and y
. Must not overlap.
§Safety
See core::ptr::
swap_nonoverlapping
.
Sourcepub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize)
Available on unsafe··
only.
pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize)
unsafe··
only.Sets count * size_of::<T>()
bytes of memory starting at dst
to val
.
§Safety
See core::ptr::
write_bytes
.
Sourcepub unsafe fn write_unaligned<T>(dst: *mut T, src: T)
Available on unsafe··
only.
pub unsafe fn write_unaligned<T>(dst: *mut T, src: T)
unsafe··
only.Overwrites a memory location with src
without reading or dropping.
§Safety
See core::ptr::
write_unaligned
.
Sourcepub unsafe fn write_volatile<T>(dst: *mut T, src: T)
Available on unsafe··
only.
pub unsafe fn write_volatile<T>(dst: *mut T, src: T)
unsafe··
only.Performs a volatile write of a memory location with src
without reading or dropping.
§Safety
See core::ptr::
write_volatile
.
Auto Trait Implementations§
impl Freeze for Ptr
impl RefUnwindSafe for Ptr
impl Send for Ptr
impl Sync for Ptr
impl Unpin for Ptr
impl UnwindSafe for Ptr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more