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

Use axum types when axum feature is enabled? #1

Open
MichielHegemans opened this issue Jan 10, 2024 · 4 comments
Open

Use axum types when axum feature is enabled? #1

MichielHegemans opened this issue Jan 10, 2024 · 4 comments
Assignees

Comments

@MichielHegemans
Copy link

Hey,

I was wondering if it is possible to make it so that when you have the axum feature enabled for the crate that you can use axum types in methods such as:

ProblemDetails::from_status_code(StatusCode::BAD_REQUEST);
ProblemDetails::new().with_type(Uri::from_static("https://example.com/errors/example"));

Rather than the required http package versions.

@frenetisch-applaudierend
Copy link
Owner

Hi @MichielHegemans

I would say that should be possible, since axum simply re-exports those types. Did you try but got an error?

@MichielHegemans
Copy link
Author

MichielHegemans commented Jan 10, 2024

Yeah seems like it. I get the following error:

error[E0308]: mismatched types
   --> web/src/lib.rs:56:42
    |
56  |         ProblemDetails::from_status_code(StatusCode::BAD_REQUEST)
    |         -------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^ expected `http::status::StatusCode`, found `StatusCode`
    |         |
    |         arguments to this function are incorrect
    |
    = note: `StatusCode` and `http::status::StatusCode` have similar names, but are actually distinct types
note: `StatusCode` is defined in crate `http`
   --> /Users/michielhegemans/.cargo/registry/src/index.crates.io-6f17d22bba15001f/http-1.0.0/src/status.rs:45:1
    |
45  | pub struct StatusCode(NonZeroU16);
    | ^^^^^^^^^^^^^^^^^^^^^
note: `http::status::StatusCode` is defined in crate `http`
   --> /Users/michielhegemans/.cargo/registry/src/index.crates.io-6f17d22bba15001f/http-0.2.11/src/status.rs:45:1
    |
45  | pub struct StatusCode(NonZeroU16);
    | ^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `http` are being used?
note: associated function defined here
   --> /Users/michielhegemans/.cargo/registry/src/index.crates.io-6f17d22bba15001f/problem_details-0.5.1/src/problem_details.rs:173:12
    |
173 |     pub fn from_status_code(status: StatusCode) -> Self {
    |            ^^^^^^^^^^^^^^^^

They are both defined as StatusCode(NonZeroU16), but they are different somehow.

I am using the following dependencies:

axum = { version = "0.7.3", features = ["form"] }
problem_details = { version = "0.5.1", features = ["axum"] }

Is it possible that axum is using a different version of http?

Nevermind, they are clearly using different versions, 1.0.0 vs 0.2.11 😂

@frenetisch-applaudierend
Copy link
Owner

Ah I see that http has updated. I think it should be straightforward to update to http 1.0. I'll look into it this evening.

Just as a side note: I'm happy you're working with my crate, just be warned that it is not so much in use yet, bugs may hide ;-) That said, if you run into any problems I'm happy to help!

@frenetisch-applaudierend
Copy link
Owner

@MichielHegemans I just released v0.6.0 which depends on http 1.0 as well as axum 0.7 which should fix the problem you're seeing.

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

No branches or pull requests

2 participants