Skip to content

Comments

Implement TryFrom for a variety of types#139

Merged
briansmith merged 2 commits intobriansmith:masterfrom
mattmahn:try-from
Jan 12, 2021
Merged

Implement TryFrom for a variety of types#139
briansmith merged 2 commits intobriansmith:masterfrom
mattmahn:try-from

Conversation

@mattmahn
Copy link
Contributor

This adds TryFrom implementations for a variety of types that already had equivalent implementations, but outside of an imply TryFrom.

I'm unsure about adding #[deprecated], since those who elevate deprecation warning to compile error may have to use core::convert::TryFrom.

related to #73

src/time.rs Outdated
@@ -47,9 +44,7 @@ impl Time {
/// ```
#[cfg(feature = "std")]
pub fn try_from(time: std::time::SystemTime) -> Result<Time, ring::error::Unspecified> {
Copy link
Owner

Choose a reason for hiding this comment

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

Go ahead and just remove this function.

Copy link
Contributor Author

@mattmahn mattmahn Jan 10, 2021

Choose a reason for hiding this comment

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

Sounds good; I kept it just in case needing to add use std::convert::TryFrom would be considered a breaking change

@codecov
Copy link

codecov bot commented Jan 10, 2021

Codecov Report

Merging #139 (cea78b0) into master (28951a0) will decrease coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #139      +/-   ##
==========================================
- Coverage   73.91%   73.76%   -0.15%     
==========================================
  Files          14       14              
  Lines        1357     1361       +4     
==========================================
+ Hits         1003     1004       +1     
- Misses        354      357       +3     
Impacted Files Coverage Δ
src/time.rs 100.00% <100.00%> (ø)
src/webpki.rs 100.00% <100.00%> (ø)
tests/integration.rs 100.00% <100.00%> (ø)
src/error.rs 66.66% <0.00%> (-16.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28951a0...cea78b0. Read the comment docs.

@mattmahn mattmahn requested a review from briansmith January 10, 2021 01:17
Copy link
Owner

@briansmith briansmith left a comment

Choose a reason for hiding this comment

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

Thanks! I'm glad this cleanup is being done. Just a few small details to clean up and then I'll merge this.

src/webpki.rs Outdated
/// `cert_der`.
pub fn from(cert_der: &'a [u8]) -> Result<Self, Error> {
EndEntityCert::try_from(cert_der)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry I wasn't clear in the earlier review. We should also delete this alternative so that TryFrom is the only way to construct a EndEntityCert.

#[cfg(feature = "std")]
#[test]
fn time_constructor() {
use std::convert::TryFrom;
Copy link
Owner

Choose a reason for hiding this comment

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

Again. let's use core:: instead of std:: consistently.

src/webpki.rs Outdated
}

impl<'a> EndEntityCert<'a> {
impl<'a> TryFrom<&'a [u8]> for EndEntityCert<'a> {
Copy link
Owner

Choose a reason for hiding this comment

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

NIT: In the other implementation you used impl ... core::convert::TryFrom and here you used use ::cure::convert::TryFrom and then the impl is unqualified. I think we should be consistent.

@mattmahn mattmahn requested a review from briansmith January 12, 2021 07:17
@briansmith briansmith merged commit 82c2e0b into briansmith:master Jan 12, 2021
@mattmahn mattmahn deleted the try-from branch January 12, 2021 22:49
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.

2 participants