Skip to content

Conversation

tarcieri
Copy link
Member

Also makes as_flattened(_mut) into const fn.

This uses the same approach as slice_as_flattened(_mut) (#144), but constructs a slice of size U::USIZE.

Also makes `as_flattened(_mut)` into `const fn`.

This uses the same approach as `slice_as_flattened(_mut)` (#144), but
constructs a slice of size `U::USIZE`.
@tarcieri tarcieri requested a review from newpavlov September 23, 2025 15:00
Comment on lines +201 to 211
/// Returns a pointer to the start of the array.
#[allow(trivial_casts)]
pub const fn as_ptr(&self) -> *const T {
self as *const Self as *const T
}

/// Returns a mutable pointer to the start of the array.
#[allow(trivial_casts)]
pub const fn as_mut_ptr(&mut self) -> *mut T {
self as *mut Self as *mut T
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the signature from the slice primitive's as_ptr method, which is what you get when you invoke it on an array due to the unsized coercion

@tarcieri tarcieri merged commit 6346ecb into master Sep 23, 2025
14 checks passed
@tarcieri tarcieri deleted the const-fn-slice-and-ptr-methods branch September 23, 2025 15:15
@tarcieri tarcieri changed the title Add as_ptr(_mut); make as_slice(_mut) into const fn Add as_(mut_)ptr; make as_(mut_)slice into const fn Sep 23, 2025
@tarcieri tarcieri mentioned this pull request Sep 23, 2025
tarcieri added a commit that referenced this pull request Sep 23, 2025
### Added
- `Array::as_(mut_)ptr` (#147)

### Changed
- Remove bounds on `Array::slice_as_flattened(_mut)`; make `const fn` (#144)
- Make `Array::as_(mut_)slice` a `const fn` (#147)
- Make `Array::<Array<T, U>::as_flattened(_mut)` a `const fn` (#147)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants