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

zerocopy: Deprecate Ref::cast and introduce the safer Ref::coerce #62

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

udoprog
Copy link
Owner

@udoprog udoprog commented Nov 13, 2023

This pull request adds Ref::coerce and Ref::try_coerce which are a series of valid conversion.

These methods accomplishes a few things:

  • It ensures that common types which have the same size can be coerced to and from each other.
  • It defines slice coercions which adjust the size of slices, for example when [T] to [U] conversions are performed. The important aspect here is the pointed-to data.
  • Defines a single generic API for performing "valid conversion" for APIs which are interested in that, such as the newly introduced trie which only cares about the byte representation of its strings.

Since coercions might overflow, Ref::try_coerce is available which returns None if metadata coercion overflows.

@udoprog udoprog added the enhancement New feature or request label Nov 13, 2023
@udoprog udoprog merged commit 15b5422 into main Nov 13, 2023
3 checks passed
@udoprog udoprog deleted the ref-coercion branch November 13, 2023 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant