-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add deconstructing conversions for owned Elements #890
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #890 +/- ##
=======================================
Coverage 77.85% 77.86%
=======================================
Files 136 136
Lines 34703 34727 +24
Branches 34703 34727 +24
=======================================
+ Hits 27017 27039 +22
- Misses 5683 5685 +2
Partials 2003 2003 ☔ View full report in Codecov by Sentry. |
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.
Overall, looks good. I could see some of these maybe being better served by a From
implementation, such as into_value
and into_bytes
. What do you think?
src/types/bytes.rs
Outdated
pub fn into_bytes(self) -> Vec<u8> { | ||
self.data | ||
} |
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.
What are your thoughts on into_bytes()
vs impl From<Bytes> for Vec<u8>
? It might be more ergonomic because then Bytes
could be passed to a function that accepts Into<Vec<u8>>
. On the other hand, if we think we might ever have a lazy Bytes
, then maybe it's best to leave it the way it is. @zslayton what do you think?
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.
impl From<Element> for Value
conflicts with the already present Value
to Element
From
implementation.
// Anything that can be turned into a `Value` can then be turned into an `Element`
// by associating it with an empty annotations sequence.
impl<T> From<T> for Element
where
T: Into<Value>,
{
fn from(value: T) -> Self {
Element::new(Annotations::empty(), value.into())
}
}
impl From<Element> for Value {
fn from(element: Element) -> Self {
element.value
}
}
error[E0119]: conflicting implementations of trait `From<element::Element>` for type `element::Element`
--> src/element/mod.rs:973:1
|
973 | / impl<T> From<T> for Element
974 | | where
975 | | T: Into<Value>,
| |___________________^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
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.
I have changed the into_bytes
into a From<Bytes> for Vec<u8>
, though I could change it back if desired (or have both). It was inspired by https://doc.rust-lang.org/std/string/struct.String.html#method.into_bytes
c398db2
to
ed56ad0
Compare
Allows deconstruction owned
Element
s andBytes
into their contained data.See also previous enhancements to ergonomics of owned
Element
sCf. #858
Cf. #866
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.