Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow casting between slices of ZSTs and slices of non-ZSTs in all cases. #256

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

zachs18
Copy link
Contributor

@zachs18 zachs18 commented Jul 28, 2024

Closes #253.

having ZST slices turn into 0-length non-ZST slices does seem like a compelling path.

This PR implements that. Additionally, casting non-ZST slices to ZST slices will work iff the input slice has length 0, and results in a slice length of 0; if the input slice is not of length 0, PodCastError::OutputSliceWouldHaveSlop is returned.

Updates the docs of the PodCastError variants to reflect when they can occur.
Updates the docs of try_cast_slice (and checked::) to remove note about ZST <-> non-ZST not being allowed.
Update bytes_of(_mut) to remove ZST-may-not-have-same-address exception, since casting [ZST] -> [u8] is now allowed directly using cast_slice(_mut) (but does not remove the documentation of the exception just in case).
Update must_cast_slice checks and doctests to allow [ZST] -> [non-ZST], but disallow [non-ZST] -> [ZST].

…ses.

Casting ZST to non-ZST will result in a slice length of 0.
Casting non-ZST to ZST will only work if the input slice has length 0, and results in a slice length of 0; if the input slice is not of length 0, PodCastError::OutputSliceWouldHaveSlop is returned.

Updates the docs of the PodCastError variants to reflect when they can occur.
Updates the docs of try_cast_slice (and checked::) to remove note about ZST <-> non-ZST not being allowed.
Update bytes_of(_mut) to remove ZST check, since casting [ZST] -> [u8] is now allowed directly using cast_slice(_mut).
Update must_cast_slice checks and doctests to allow [ZST] -> [non-ZST], but disallow [non-ZST] -> [ZST].
@Lokathor Lokathor merged commit 291a924 into Lokathor:main Jul 30, 2024
14 checks passed
@zachs18 zachs18 mentioned this pull request Jul 31, 2024
@Lokathor Lokathor added the semver-patch semver patch change label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch semver patch change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zero-sized type (ZST) handling inconsistency between borrowed and owned slice casts.
2 participants