Skip to content
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

feat(typed_header_rejection): add is_missing utility to the reason #2503

Merged
merged 1 commit into from Jan 10, 2024

Conversation

joshuachp
Copy link
Contributor

@joshuachp joshuachp commented Jan 10, 2024

Motivation

It's hard, when creating your own extractor, to check if a TypedHeader is missing or there was an actual error. The TypedHeaderRejectionReason doesn't/can't implement PartialEq since it include the headers_core::Error variant, so you need to add a match to check.

match typed_header {
   Ok(_) => todo!(),
   Err(err) if matches!(err.reason(), TypedHeaderRejectionReason::Missing)  => todo!(),
   Err(_) => todo!()
}

Solution

Add a utility function to check if the TypedHeaderRejection is missing. Example:

match typed_header {
   Ok(_) => todo!(),
   Err(err) if err.is_missing() => todo!(),
   Err(err) => todo!()
}

Copy link
Member

@davidpdrsn davidpdrsn left a comment

Choose a reason for hiding this comment

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

Looks good! Wanna update the changelog as well?

Add a utility function to check if the `TypedHeaderRejectionReason` is
missing since it doesn't/can't implement PartialEq.
@joshuachp
Copy link
Contributor Author

Updated the CHANGELOG

@jplatte jplatte merged commit 791d503 into tokio-rs:main Jan 10, 2024
18 checks passed
@joshuachp joshuachp deleted the feature/typed-header-missing branch January 10, 2024 11:17
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.

None yet

3 participants