Skip to main content

LocalUser

Struct LocalUser 

Source
pub struct LocalUser<T> {
    pub(super) ptr: T,
}
Available on crate feature full only.

Fields§

§ptr: T

Implementations§

Source§

impl<T: ?Sized> LocalUser<*const T>

Source

pub unsafe fn new(addr: usize) -> Self
where T: Sized,

Creates a new LocalUser<*const T> with tied to the current address space

§Safety

addr, if valid, must point to a valid bit pattern for T in the current address space. This means that in almost all cases, it is unsound to create a LocalUser<*const T> where T has a niche.

For all types with no invalid bit-patterns (i.e. all numeric types) it is sound to create a LocalUser<*const T>.

Source

pub const fn is_null(&self) -> bool

Returns true if the pointer has a null address

Source

pub const unsafe fn offset(self, count: isize) -> Self
where T: Sized,

Adds a signed offset to a pointer.

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

§Safety

See safety requirements for [<*const T>::offset()]

Source

pub const unsafe fn byte_offset(self, count: isize) -> Self

Adds a signed offset in bytes to a pointer.

§Safety

See safety requirements for [<*const T>::byte_offset()]

Source

pub const unsafe fn add(self, count: usize) -> Self
where T: Sized,

Adds an offset to a pointer.

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

§Safety

See safety requirements for [<*const T>::add()]

Source

pub const unsafe fn byte_add(self, count: usize) -> Self

Adds an offset in bytes to a pointer.

§Safety

See safety requirements for [<*const T>::byte_add()]

Source

pub const unsafe fn sub(self, count: usize) -> Self
where T: Sized,

Subtracts an offset from a pointer.

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

§Safety

See safety requirements for [<*const T>::sub()]

Source

pub const unsafe fn byte_sub(self, count: usize) -> Self

Subtracts an offset in bytes from a pointer.

§Safety

See safety requirements for [<*const T>::byte_sub()]

Source

pub fn read(self) -> Result<T, PointerError>
where T: Sized + Copy,

Tries to read the value pointed to by the pointer

§Errors

If the pointer is invalid due to unmapped memory or similar, returns PointerError

Source

pub const unsafe fn cast<U>(self) -> LocalUser<*const U>

Casts a pointer to another type

§Safety

If self has a valid address, then it must point to a valid bit pattern for U in the current address space. This means that in almost all cases, it is unsound to cast to a LocalUser<*const U> where U has a niche.

For all types with no invalid bit-patterns (i.e. all numeric types) it is sound to cast to a User<*const U>.

Source

pub const fn cast_mut(self) -> LocalUser<*mut T>

Casts to a writable pointer

Source

pub fn is_aligned_to(self, align: usize) -> bool

Source

pub fn addr(self) -> VirtualAddress

Source

pub fn align_offset(self, align: usize) -> usize
where T: Sized,

Source§

impl<T: ?Sized> LocalUser<*mut T>

Source

pub fn new(addr: usize) -> Self
where T: Sized,

Creates a new LocalUser<*mut T> with the provided address tied to the current address space

Source

pub const fn is_null(&self) -> bool

Returns true if the pointer has a null address

Source

pub const unsafe fn offset(self, count: isize) -> Self
where T: Sized,

Adds a signed offset to a pointer.

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

§Safety

See safety requirements for [<*mut T>::offset()]

Source

pub const unsafe fn byte_offset(self, count: isize) -> Self

Adds a signed offset in bytes to a pointer.

§Safety

See safety requirements for [<*mut T>::byte_offset()]

Source

pub const unsafe fn add(self, count: usize) -> Self
where T: Sized,

Adds an offset to a pointer.

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

§Safety

See safety requirements for [<*mut T>::add()]

Source

pub const unsafe fn byte_add(self, count: usize) -> Self

Adds an offset in bytes to a pointer.

§Safety

See safety requirements for [<*mut T>::byte_add()]

Source

pub const unsafe fn sub(self, count: usize) -> Self
where T: Sized,

Subtracts an offset from a pointer.

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

§Safety

See safety requirements for [<*mut T>::sub()]

Source

pub const unsafe fn byte_sub(self, count: usize) -> Self

Subtracts an offset in bytes from a pointer.

§Safety

See safety requirements for [<*mut T>::byte_sub()]

Source

pub fn write(self, value: T) -> Result<(), PointerError>
where T: Sized,

Tries to write to the value pointed to by the pointer

§Errors

If the pointer is invalid due to unmapped memory or similar, returns PointerError

Source

pub const fn cast<U>(self) -> LocalUser<*mut U>

Casts a pointer to another type

Source

pub const unsafe fn cast_const(self) -> LocalUser<*const T>

Casts to a readable pointer

§Safety

addr, if valid, must point to a valid bit pattern for T in the current address space. This means that in almost all cases, it is unsound to cast to a LocalUser<*const T> where T has a niche.

For all types with no invalid bit-patterns (i.e. all numeric types) it is sound to cast to a LocalUser<*const T>.

Source

pub fn is_aligned_to(self, align: usize) -> bool

Source

pub fn addr(self) -> VirtualAddress

Source

pub fn align_offset(self, align: usize) -> usize
where T: Sized,

Source§

impl<T> LocalUser<*const [T]>

Source

pub const fn len(self) -> usize

Source

pub const fn is_empty(self) -> bool

Source

pub const fn as_ptr(self) -> LocalUser<*const T>

Source

pub fn read_to_box(self) -> Result<Box<[T]>, PointerError>

Source

pub fn read_to_buffer( self, buffer: &mut [MaybeUninit<T>], ) -> Result<usize, PointerError>

Source§

impl<T> LocalUser<*mut [T]>

Source

pub const fn len(self) -> usize

Source

pub const fn is_empty(self) -> bool

Source

pub const fn as_mut_ptr(self) -> LocalUser<*mut T>

Source

pub fn write_from_slice(self, slice: &[T]) -> Result<usize, PointerError>

Trait Implementations§

Source§

impl<T: Clone> Clone for LocalUser<T>

Source§

fn clone(&self) -> LocalUser<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable)§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Pointer> Debug for LocalUser<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Pointer> Pointer for LocalUser<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized> TryFrom<User<'_, *const T>> for LocalUser<*const T>

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: User<'_, *const T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: ?Sized> TryFrom<User<'_, *mut T>> for LocalUser<*mut T>

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: User<'_, *mut T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: Copy> Copy for LocalUser<T>

Source§

impl<T> !Send for LocalUser<T>

Source§

impl<T> !Sync for LocalUser<T>

Auto Trait Implementations§

§

impl<T> Freeze for LocalUser<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for LocalUser<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for LocalUser<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for LocalUser<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for LocalUser<T>
where T: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.