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

axum-macros: use fully qualified Result type #796

Merged
merged 1 commit into from
Feb 26, 2022

Conversation

matze
Copy link
Contributor

@matze matze commented Feb 25, 2022

Motivation

It is pretty common to define custom Result<T> type aliases however the typed_path macros generate Result<T, E> on the assumption they are imported from the std prelude. Having the type aliases defined causes errors like:

 #[derive(TypedPath, Deserialize)]
          ^^^^^^^^^
          |
          expected 1 generic argument
          help: remove this generic argument

Solution

Generate fully qualified std::result::Result return types.

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.

Thanks! Guessed we missed these.

@jplatte
Copy link
Member

jplatte commented Feb 26, 2022

By the way, it doesn't make this PR less valid but many people now prefer

type Result<T, E = MyError> = std::result::Result<T, E>;

over

type Result<T> = std::result::Result<T, MyError>;

The former allows you to write both Result<Ok, Err> or Result<Ok> without the extra qualification.

Using the Result type from the prelude clashes with custom Result type
aliases causing errors like this:

     #[derive(TypedPath, Deserialize)]
              ^^^^^^^^^
              |
              expected 1 generic argument
              help: remove this generic argument
@matze matze force-pushed the fix-with-redefined-result-types branch from 708fd9b to 03348f9 Compare February 26, 2022 12:14
@matze
Copy link
Contributor Author

matze commented Feb 26, 2022

By the way, it doesn't make this PR less valid but many people now prefer

type Result<T, E = MyError> = std::result::Result<T, E>;

Good point, yes.

@davidpdrsn davidpdrsn merged commit 67c385c into tokio-rs:main Feb 26, 2022
@matze matze deleted the fix-with-redefined-result-types branch February 27, 2022 12:30
davidpdrsn added a commit that referenced this pull request Mar 1, 2022
* axum-macros: use fully qualified Result type (#796)

* Easily convert typed paths into URIs (#790)

* Easily convert typed paths into URIs

`#[derive(TypedPath)]` will now also generate `TryFrom<_> for Uri` for
easily converting paths into URIs for use with `Redirect` and friends.

Fixes #789

* Use a method on the `TypedPath` trait to convert to `Uri`

* fix doc ref

* Update changelogs

* Remove out of date docs

These accidentally weren't removed in #790

Co-authored-by: Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
davidpdrsn added a commit that referenced this pull request Mar 1, 2022
- **fixed:** Use fully qualified `Result` type ([#796])

[#796]: #796
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.

3 participants