Skip to content

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Nov 7, 2025

Adds an associated CAN_READ_SLICE boolean flag to the Reader trait.

When false, Cow decodes the owned type rather than the borrow one.

This makes it possible to use Cow with PemReader, where it will automatically decode the owned type.

Adds an associated `CAN_READ_SLICE` boolean flag to the `Reader` trait.

When false, `Cow` decodes the owned type rather than the borrow one.

This makes it possible to use `Cow` with `PemReader`, where it will
automatically decode the owned type.

#[cfg(feature = "alloc")]
impl<'a, T> DecodeValue<'a> for Cow<'a, T>
impl<'a, T, E> DecodeValue<'a> for Cow<'a, T>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still somewhat annoyingly ties the lifetime of the Cow to the lifetime of the Reader, which for PemReader is still the lifetime of the input buffer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, that's easily fixable by making it impl Reader<'static> instead

T: ToOwned + ?Sized,
&'a T: DecodeValue<'a>,
&'a T: DecodeValue<'a, Error = E>,
T::Owned: for<'b> DecodeValue<'b, Error = E>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, it's HRTB

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really necessary here to show that the output lifetime is independent of the input lifetimes, which should let Reader<'static> work when decoding Cow<'static, T>

@tarcieri tarcieri merged commit 0c63159 into master Nov 7, 2025
107 checks passed
@tarcieri tarcieri deleted the der/cow-decode-owned-from-pem-reader branch November 7, 2025 23:58
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.

3 participants