Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented May 8, 2024

This allows us to more strictly enforce the requirement that, for Ref's ByteSlice field, methods are never called other than those defined on the ByteSlice, ByteSliceMut, IntoByteSlice, and IntoByteSliceMut traits. We accomplish this by keeping the field private, and only exposing unsafe getters which return, for example, &impl ByteSlice.

We also introduce new traits - CopyableByteSlice and CloneableByteSlice. We tighten the Copy and Clone impls for Ref to require these bounds. Previously, ByteSlice required that its "dereference stability" requirement applied to any Copy or Clone impls, but this would have prevented us from implementing ByteSlice for Vec. By splitting the requirement into separate traits, we open the door to supporting Vec (#992).

@joshlf joshlf force-pushed the ref-module-privacy branch 3 times, most recently from 3e8f3c4 to 36159b7 Compare May 8, 2024 20:30
@joshlf joshlf requested a review from jswrenn May 8, 2024 20:30
@joshlf joshlf marked this pull request as ready for review May 8, 2024 20:31
@joshlf joshlf enabled auto-merge May 8, 2024 20:31
@joshlf joshlf force-pushed the ref-module-privacy branch from 36159b7 to d7ccc5a Compare May 8, 2024 20:41
@joshlf joshlf force-pushed the ref-module-privacy branch from d7ccc5a to 475e6e1 Compare May 9, 2024 15:54
This allows us to more strictly enforce the requirement that, for
`Ref`'s `ByteSlice` field, methods are never called other than those
defined on the `ByteSlice`, `ByteSliceMut`, `IntoByteSlice`, and
`IntoByteSliceMut` traits. We accomplish this by keeping the field
private, and only exposing unsafe getters which return, for example,
`&impl ByteSlice`.

We also introduce new traits - `CopyableByteSlice` and
`CloneableByteSlice`. We tighten the `Copy` and `Clone` impls for `Ref`
to require these bounds. Previously, `ByteSlice` required that its
"dereference stability" requirement applied to any `Copy` or `Clone`
impls, but this would have prevented us from implementing `ByteSlice`
for `Vec`. By splitting the requirement into separate traits, we open
the door to supporting `Vec` (#992).
@joshlf joshlf force-pushed the ref-module-privacy branch from 475e6e1 to 0461109 Compare May 9, 2024 16:24
@joshlf joshlf requested a review from jswrenn May 9, 2024 16:25
@joshlf joshlf added this pull request to the merge queue May 9, 2024
Merged via the queue into main with commit 1e35482 May 9, 2024
@joshlf joshlf deleted the ref-module-privacy branch May 9, 2024 16:44
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