Skip to content

Add functions for casting from core references#181

Merged
tarcieri merged 1 commit intomasterfrom
cast-from-core-ref-and-mut
Mar 29, 2026
Merged

Add functions for casting from core references#181
tarcieri merged 1 commit intomasterfrom
cast-from-core-ref-and-mut

Conversation

@tarcieri
Copy link
Copy Markdown
Member

  • Array::cast_from_core: const fn equivalent of From<[T; N]>
  • Array::cast_from_core_mut: mut equivalent of the above
  • Array::from_ref: cast &T to &Array<T; U1>
  • Array::from_mut: mut equivalent of the above

The latter are the equivalents of core::array::{from_ref, from_mut} which I opted to put on Array<T, U1> for consistency with Array::from_fn which is impl'd on the type instead of as a free function.

- `Array::cast_from_core`: `const fn` equivalent of `From<[T; N]>`
- `Array::cast_from_core_mut`: `mut` equivalent of the above
- `Array::from_ref`: cast `&T` to `&Array<T; U1>`
- `Array::from_mut`: `mut` equivalent of the above

The latter are the equivalents of `core::array::{from_ref, from_mut}`
which I opted to put on `Array<T, U1>` for consistency with
`Array::from_fn` which is impl'd on the type instead of as a free
function.
@tarcieri tarcieri merged commit 7569e51 into master Mar 29, 2026
14 checks passed
@tarcieri tarcieri deleted the cast-from-core-ref-and-mut branch March 29, 2026 12:39
@tarcieri tarcieri mentioned this pull request Mar 30, 2026
tarcieri added a commit that referenced this pull request Mar 30, 2026
## Added
- Functions for casting from core references (#181)
  - `Array::cast_from_core`: `const fn` equivalent of `From<[T; N]>`
  - `Array::cast_from_core_mut`: `mut` equivalent of the above
  - `Array::from_ref`: cast `&T` to `&Array<T; U1>`
  - `Array::from_mut`: `mut` equivalent of the above
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