pub struct User<'a, T> {
ptr: T,
address_space: Option<&'a AddressSpace>,
}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>
impl<'a, T: ?Sized> User<'a, *const T>
Sourcepub(crate) unsafe fn new(ptr: *const T, address_space: &'a AddressSpace) -> Selfwhere
T: Sized,
pub(crate) unsafe fn new(ptr: *const T, address_space: &'a AddressSpace) -> Selfwhere
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>.
Sourcepub const fn is_null(&self) -> bool
pub const fn is_null(&self) -> bool
Returns true if the pointer has either a null address or address space
Sourcepub const unsafe fn offset(self, count: isize) -> Selfwhere
T: Sized,
pub const unsafe fn offset(self, count: isize) -> Selfwhere
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()]
Sourcepub const unsafe fn byte_offset(self, count: isize) -> Self
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()]
Sourcepub const unsafe fn add(self, count: usize) -> Selfwhere
T: Sized,
pub const unsafe fn add(self, count: usize) -> Selfwhere
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()]
Sourcepub const unsafe fn sub(self, count: usize) -> Selfwhere
T: Sized,
pub const unsafe fn sub(self, count: usize) -> Selfwhere
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()]
Sourcepub const unsafe fn byte_sub(self, count: usize) -> Self
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()]
pub fn read_other_address_space(self) -> Result<T, PointerError>where
T: Sized + Copy,
Sourcepub const unsafe fn cast<U>(self) -> User<'a, *const U>
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>.
pub fn is_aligned_to(self, align: usize) -> bool
pub fn addr(self) -> VirtualAddress
pub fn align_offset(self, align: usize) -> usizewhere
T: Sized,
Source§impl<'a, T: ?Sized> User<'a, *mut T>
impl<'a, T: ?Sized> User<'a, *mut T>
Sourcepub(crate) fn new(ptr: *mut T, address_space: &'a AddressSpace) -> Selfwhere
T: Sized,
pub(crate) fn new(ptr: *mut T, address_space: &'a AddressSpace) -> Selfwhere
T: Sized,
Creates a new User<*mut T> with the provided address tied to the provided address space
Sourcepub const fn is_null(&self) -> bool
pub const fn is_null(&self) -> bool
Returns true if the pointer has either a null address or address space
Sourcepub const unsafe fn offset(self, count: isize) -> Selfwhere
T: Sized,
pub const unsafe fn offset(self, count: isize) -> Selfwhere
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()]
Sourcepub const unsafe fn byte_offset(self, count: isize) -> Self
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()]
Sourcepub const unsafe fn add(self, count: usize) -> Selfwhere
T: Sized,
pub const unsafe fn add(self, count: usize) -> Selfwhere
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()]
Sourcepub const unsafe fn sub(self, count: usize) -> Selfwhere
T: Sized,
pub const unsafe fn sub(self, count: usize) -> Selfwhere
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()]
Sourcepub const unsafe fn byte_sub(self, count: usize) -> Self
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()]
pub fn write_other_address_space(self, value: T) -> Result<(), PointerError>where
T: Sized,
pub unsafe fn copy_from_other_address_space(
self,
start: *const T,
count: usize,
) -> Result<(), PointerError>where
T: Sized,
Sourcepub const unsafe fn cast_const(self) -> User<'a, *const T>
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>.
pub fn is_aligned_to(self, align: usize) -> bool
pub fn addr(self) -> VirtualAddress
pub fn align_offset(self, align: usize) -> usizewhere
T: Sized,
Source§impl<'a, T> User<'a, *mut [T]>
impl<'a, T> User<'a, *mut [T]>
pub const fn len(self) -> usize
pub const fn is_empty(self) -> bool
pub const fn as_mut_ptr(self) -> User<'a, *mut T>
pub fn write_from_slice_other_address_space( self, slice: &[T], ) -> Result<usize, PointerError>
pub fn fill(self, value: u8) -> Result<(), PointerError>
Trait Implementations§
Source§impl<T: Thin + ?Sized> Default for User<'_, *const T>
Produces a null pointer
impl<T: Thin + ?Sized> Default for User<'_, *const T>
Produces a null pointer
See null() for more details
Source§impl<T: Thin + ?Sized> Default for User<'_, *mut T>
Produces a null pointer
impl<T: Thin + ?Sized> Default for User<'_, *mut T>
Produces a null pointer
See null_mut() for more details
Source§impl<T: ?Sized> PartialEq for User<'_, *const T>
Pointer equality is by address space, and [<*const T>::eq].
impl<T: ?Sized> PartialEq for User<'_, *const T>
Pointer equality is by address space, and [<*const T>::eq].
Source§impl<T: ?Sized> PartialEq for User<'_, *mut T>
Pointer equality is by address space, and [<*mut T>::eq].
impl<T: ?Sized> PartialEq for User<'_, *mut T>
Pointer equality is by address space, and [<*mut T>::eq].
impl<'a, T: Copy> Copy for User<'a, T>
impl<T: ?Sized> Eq for User<'_, *const T>
impl<T: ?Sized> Eq for User<'_, *mut T>
impl<T: Send + ?Sized> Send for User<'_, *const T>
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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)