Skip to main content

User

Struct User 

Source
pub struct User<'a, T> {
    ptr: T,
    address_space: Option<&'a AddressSpace>,
}
Available on crate feature full only.
Expand description

A pointer to a potentially invalid address, tied to a specific address space

While the pointer may safely point to an invalid or unaligned address, in the case that it points to a valid address and is read from, then it is unsound for the address to not hold a valid bit-pattern for the type T.

For example, it is always sound to create a User<*const u8> regardless of the address it points to, and always safe to call read() on it, but it would be unsound to create a User<*const bool>if it’s not guaranteed that the pointed value is either 1 or 0.

Additionally, to make the API require less unsafe for common cases, User<*mut T> is always safe to construct, with the additional requirement that it becomes write-only.

Fields§

§ptr: T§address_space: Option<&'a AddressSpace>

Implementations§

Source§

impl<'a, T: ?Sized> User<'a, *const T>

Source

pub(crate) unsafe fn new(ptr: *const T, address_space: &'a AddressSpace) -> Self
where T: Sized,

Creates a new User<*const T> with the provided address tied to the provided 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 User<*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 User<*const T>.

Source

pub const fn is_null(&self) -> bool

Returns true if the pointer has either a null address or address space

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_other_address_space(self) -> Result<T, PointerError>
where T: Sized + Copy,

Source

pub const unsafe fn cast<U>(self) -> User<'a, *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 User<*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) -> User<'a, *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<'a, T: ?Sized> User<'a, *mut T>

Source

pub(crate) fn new(ptr: *mut T, address_space: &'a AddressSpace) -> Self
where T: Sized,

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

Source

pub const fn is_null(&self) -> bool

Returns true if the pointer has either a null address or address space

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_other_address_space(self, value: T) -> Result<(), PointerError>
where T: Sized,

Source

pub unsafe fn copy_from_other_address_space( self, start: *const T, count: usize, ) -> Result<(), PointerError>
where T: Sized,

Source

pub const fn cast<U>(self) -> User<'a, *mut U>

Casts a pointer to another type

Source

pub const unsafe fn cast_const(self) -> User<'a, *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 User<*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 User<*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<'a, T> User<'a, *const [T]>

Source

pub const fn len(self) -> usize

Source

pub const fn is_empty(self) -> bool

Source

pub const fn as_ptr(self) -> User<'a, *const T>

Source§

impl<'a, T> User<'a, *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) -> User<'a, *mut T>

Source

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

Source

pub fn fill(self, value: u8) -> Result<(), PointerError>

Trait Implementations§

Source§

impl<'a, T: Clone> Clone for User<'a, T>

Source§

fn clone(&self) -> User<'a, 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 User<'_, T>

Source§

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

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

impl<T: Thin + ?Sized> Default for User<'_, *const T>

Produces a null pointer

See null() for more details

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Thin + ?Sized> Default for User<'_, *mut T>

Produces a null pointer

See null_mut() for more details

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Pointer equality is by address space, and [<*const T>::eq].

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable)§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Pointer equality is by address space, and [<*mut T>::eq].

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable)§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Pointer> Pointer for User<'_, 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<'a, T: Copy> Copy for User<'a, T>

Source§

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

Source§

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

Source§

impl<T: Send + ?Sized> Send for User<'_, *const T>

Source§

impl<T: Send + ?Sized> Send for User<'_, *mut T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for User<'a, T>
where T: Freeze,

§

impl<'a, T> RefUnwindSafe for User<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for User<'a, T>

§

impl<'a, T> Sync for User<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for User<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for User<'a, T>
where T: UnsafeUnpin,

§

impl<'a, T> UnwindSafe for User<'a, 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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.