-
Notifications
You must be signed in to change notification settings - Fork 170
der: have PemReader decode to Cow::Owned
#2094
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,14 +212,20 @@ where | |
| } | ||
|
|
||
| #[cfg(feature = "alloc")] | ||
| impl<'a, T> DecodeValue<'a> for Cow<'a, T> | ||
| impl<'a, T, E> DecodeValue<'a> for Cow<'a, T> | ||
| where | ||
| T: ToOwned + ?Sized, | ||
| &'a T: DecodeValue<'a>, | ||
| &'a T: DecodeValue<'a, Error = E>, | ||
| T::Owned: for<'b> DecodeValue<'b, Error = E>, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh no, it's HRTB
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| E: From<Error> + 'static, | ||
| { | ||
| type Error = <&'a T as DecodeValue<'a>>::Error; | ||
| type Error = E; | ||
|
|
||
| fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self, Self::Error> { | ||
| Ok(Cow::Borrowed(<&'a T>::decode_value(reader, header)?)) | ||
| if R::CAN_READ_SLICE { | ||
| <&'a T>::decode_value(reader, header).map(Cow::Borrowed) | ||
| } else { | ||
| T::Owned::decode_value(reader, header).map(Cow::Owned) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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
Cowto the lifetime of theReader, which forPemReaderis still the lifetime of the input buffer.There was a problem hiding this comment.
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