Skip to content

der: improved internal ref types #1921

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

Merged
merged 1 commit into from
Jul 7, 2025
Merged

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Jul 7, 2025

Changes BytesRef and StringRef from types with an explicit lifetime which act as newtypes for inner &'a [u8] and &'a str types to being newtypes for [u8] and str.

This requires a very small amount of unsafe casting, but makes it possible to implement reference conversions entirely in terms of standard traits like AsRef, Borrow, Deref, and ToOwned as opposed to using our custom RefToOwned and OwnedToReftraits. It makes it possible to use e.g.Cow` as well.

This is the first step towards moving the entire crate to this pattern and eliminating the OwnedToRef and RefToOwned raits, replacing them instead with the standard AsRef and ToOwned traits.

@tarcieri tarcieri force-pushed the der/improved-internal-ref-types branch 2 times, most recently from e1d43cb to 8976040 Compare July 7, 2025 20:40
Changes `BytesRef` and `StringRef` from types with an explicit lifetime
which act as newtypes for inner `&'a [u8]` and `&'a str` types to being
newtypes for `[u8]` and `str`.

This requires a very small amount of `unsafe` casting, but makes it
possible to implement reference conversions entirely in terms of
standard traits like `AsRef`, `Borrow`, `Deref`, and `ToOwned` as
opposed to using our custom `RefToOwned` and OwnedToRef` traits.
It makes it possible to use e.g. `Cow` as well.

This is the first step towards moving the entire crate to this pattern
and eliminating the `OwnedToRef` and `RefToOwned` raits, replacing them
instead with the standard `AsRef` and `ToOwned` traits.
@tarcieri tarcieri force-pushed the der/improved-internal-ref-types branch from 8976040 to 7284d50 Compare July 7, 2025 20:43
@tarcieri
Copy link
Member Author

tarcieri commented Jul 7, 2025

cc @dishmaker

I'm going to try to do this conversion incrementally a bit at a time. That also makes it potentially possible to split up the work.

@tarcieri tarcieri merged commit 73e513e into master Jul 7, 2025
107 checks passed
@tarcieri tarcieri deleted the der/improved-internal-ref-types branch July 7, 2025 21: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.

1 participant