http-rs / http-types

Common types for HTTP operations
https://docs.rs/http-types
Apache License 2.0
200 stars 83 forks source link

*_status macros only take numeric status codes #337

Open Fishrock123 opened 3 years ago

Fishrock123 commented 3 years ago

The _status macros, e.g. format_err_status, only take literals as the status code argument, and prevent an idiomatic usage:

format_err_status!(
    StatusCode::InternalServerError,
    "Error: {}",
    error_data
)
yoshuawuyts commented 3 years ago

Oh, yeah that indeed seems like a bug. Declarative macros can take various input types (literals, statements), and I think we may need to add new rules so they operate on all kinds.

Fishrock123 commented 3 years ago

I'm not entirely sure what it should be - we'll have to add tests for these really. Does it have to be tt? Can be less general? I don't really understand well the types that macros take, even with https://cheats.rs/#macros-attributes. Are all literals also expressions, for example?