Skip to content

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Sep 1, 2025

Provides an alternative to #133 using the less commonly used Borrow trait instead, which should still make the same patterns of exposing APIs with core arrays possible, but hopefully while causing less breakage in end user code.

Provides an alternative to #133 using the less commonly used `Borrow`
trait instead, which should still make the same patterns of exposing
APIs with core arrays possible, but hopefully while causing less
breakage in end user code.
@tarcieri tarcieri force-pushed the add-borrow-impls-for-core-arrays branch from 1f293a9 to b81b313 Compare September 1, 2025 15:00
@tarcieri tarcieri changed the title Add Borrow<Array<_, _>>/BorrowMut impls for [T; N] Add Borrow<Array<T, _>>/BorrowMut impls for [T; N] Sep 1, 2025
@tarcieri
Copy link
Member Author

tarcieri commented Sep 1, 2025

@kayabaNerve I tried this out on your code and everything seems fine. I expect since Borrow is a trait people have to import, it should cause fewer issues

@tarcieri tarcieri merged commit 1e21e27 into master Sep 1, 2025
14 checks passed
@tarcieri tarcieri deleted the add-borrow-impls-for-core-arrays branch September 1, 2025 15:12
@tarcieri
Copy link
Member Author

tarcieri commented Sep 1, 2025

I probably should've posted a potential alternative, which would be to modify the AssocArraySize trait to provide a method for obtaining &Array since it needs to be in-scope anyway. That would completely avoid anything weird involving overlapping trait impls from core.

tarcieri added a commit that referenced this pull request Sep 1, 2025
Impl'd for `Array<T, U>` and `[T; N]`.

This is an alternative to #134, given the trouble we had in #131 with
adding impls of core traits to `[T; N]` and the ensuing inference
conflicts it can cause.

The safest thing we can do is define our own traits, and these traits
bound on `AssocArraySize` so they're able to handle everything related
to the array size themselves, making them generic around only `T`.

With this we can revert #134, which still has the potential to cause
problems similar to #131. Using our own trait guarantees we won't break
inference in existing code.
tarcieri added a commit that referenced this pull request Sep 1, 2025
Impl'd for `Array<T, U>` and `[T; N]`.

This is an alternative to #134, given the trouble we had in #131 with
adding impls of core traits to `[T; N]` and the ensuing inference
conflicts it can cause.

The safest thing we can do is define our own traits, and these traits
bound on `AssocArraySize` so they're able to handle everything related
to the array size themselves, making them generic around only `T`.

With this we can revert #134, which still has the potential to cause
problems similar to #131. Using our own trait guarantees we won't break
inference in existing code.
tarcieri added a commit that referenced this pull request Sep 1, 2025
Impl'd for `Array<T, U>` and `[T; N]`.

This is an alternative to #134, given the trouble we had in #131 with
adding impls of core traits to `[T; N]` and the ensuing inference
conflicts it can cause.

The safest thing we can do is define our own traits, and these traits
bound on `AssocArraySize` so they're able to handle everything related
to the array size themselves, making them generic around only `T`.

With this we can revert #134, which still has the potential to cause
problems similar to #131. Using our own trait guarantees we won't break
inference in existing code.
tarcieri added a commit that referenced this pull request Sep 1, 2025
Impl'd for `Array<T, U>` and `[T; N]`.

This is an alternative to #134, given the trouble we had in #131 with
adding impls of core traits to `[T; N]` and the ensuing inference
conflicts it can cause.

The safest thing we can do is define our own traits, and these traits
bound on `AssocArraySize` so they're able to handle everything related
to the array size themselves, making them generic around only `T`.

With this we can revert #134, which still has the potential to cause
problems similar to #131. Using our own trait guarantees we won't break
inference in existing code.
tarcieri added a commit that referenced this pull request Sep 1, 2025
This reverts commit 1e21e27 (#134)

To avoid any future inference problems like #131.

Instead #135 adds traits impl'd on `[T; N]` which provide equivalent
functionality.
tarcieri added a commit that referenced this pull request Sep 1, 2025
This reverts commit 1e21e27 (#134)

To avoid any future inference problems like #131.

Instead #135 adds traits impl'd on `[T; N]` which provide equivalent
functionality.
@kayabaNerve
Copy link

kayabaNerve commented Sep 1, 2025

I do have some code that uses Borrow but yes, it's farrrrr less prevalent and .borrow() is an explicit import of the Borrow trait to access. Shifting from a 'hot' trait to a 'cold' trait, to offer the functionality albeit with less likelihood of conflict to shift the costs/rewards, sounds great to me.

Using hybrid-array traits also sounds perfect, but I'll leave it to you.

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