Skip to content

Make statuscode from u16 in error#216

Merged
yoshuawuyts merged 2 commits intohttp-rs:masterfrom
yusuke-ota:make_statuscode_from_u16_in_error
Aug 7, 2020
Merged

Make statuscode from u16 in error#216
yoshuawuyts merged 2 commits intohttp-rs:masterfrom
yusuke-ota:make_statuscode_from_u16_in_error

Conversation

@yusuke-ota
Copy link
Copy Markdown
Contributor

@yusuke-ota yusuke-ota commented Aug 7, 2020

Enable http-types::Error::new(u16, Error), http-types::Error::from_str(u16, &str)

Description

Change Error::new(StatusCode, impl Into<anyhow::Error>) to Error::new(impl TryInto<StatusCode>, impl Into<anyhow::Error>).

Maybe, new tests I added are needless.
Before this pull request merge, please tell me. I`ll remove them.

Motivation and Context

A Part of tide#649

This enable Error::new(u16, error) like Response::new(u16).

How Has This Been Tested?

Add tests.
But, maybe these tests are needless after marge.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

change status that Error::new and Error::from_str argument
status: StatusCode
->
status: S
S: TryInto<StatusCode>
S::Error: Debug
Copy link
Copy Markdown
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

A few nits; but this looks 💯 overall!

tests/error.rs Outdated
#[should_panic]
fn fail_test_u16_into_status_code_in_http_types_error_from_str() {
let _http_types_error = Error::from_str(1000, "Un Existed");
} No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a newline here?

@yusuke-ota
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing. Your suggestion commit at f26568c.
If tests I added are needless, Please tell me.
If not, please merge this.

Copy link
Copy Markdown
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

💯 thanks so much!

@yoshuawuyts yoshuawuyts merged commit d4f85be into http-rs:master Aug 7, 2020
@yusuke-ota yusuke-ota deleted the make_statuscode_from_u16_in_error branch August 8, 2020 01:10
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