Skip to content

Tracking Issue for convenience methods on NonNull #117691

Closed
@WaffleLapkin

Description

@WaffleLapkin

Feature gate: #![feature(non_null_convenience)]

This is a tracking issue for convenience methods on NonNull.

Public API

// core::ptr

impl<T: Sized> NonNull<T> {
    pub const unsafe fn offset(self, count: isize) -> NonNull<T>;
    pub const unsafe fn add(self, count: usize) -> NonNull<T>;
    pub const unsafe fn sub(self, count: usize) -> NonNull<T>;

    pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize;
    pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize;

    pub const unsafe fn read(self) -> T;
    pub unsafe fn read_volatile(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;

    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);
    pub const unsafe fn write(self, val: T); 
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
    pub unsafe fn write_volatile(self, val: T);
    pub const unsafe fn write_unaligned(self, val: T);
    pub unsafe fn replace(self, src: T) -> T;
    pub const unsafe fn swap(self, with: NonNull<T>);

    pub const fn align_offset(self, align: usize) -> usize;
    pub const fn is_aligned(self) -> bool;    
}
    
impl<T: ?Sized> NonNull<T> {
    pub const unsafe fn byte_offset(self, count: isize) -> NonNull<T>;
    pub const unsafe fn byte_add(self, count: usize) -> NonNull<T>;
    pub const unsafe fn byte_sub(self, count: usize) -> NonNull<T>;

    pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize;

    pub unsafe fn drop_in_place(self);

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

(I'll fill the API once PR is merged, stand-by...)

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-raw-pointersArea: raw pointers, MaybeUninit, NonNullC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions