I want to create a structure called Timeout
that is exactly std::time::Duration
but implement Display
trait for it.
Background
I want to use the query_params crate on my structure that looks like:
#[macro_use]
extern crate query_params;
use std::time::Duration;
#[derive(QueryParams)]
struct PullRequestsParametersApi {
page: Option<i32>,
timeout: Option<Duration>,
}
fn main() {
let pr = PullRequestsParametersApi {
page: Some(32),
timeout: None,
};
println!("Query= {} <<end", pr.to_query_params());
}
This causes a compiler error:
--> src/main.rs:5:10
|
5 | #[derive(QueryParams)]
| ^^^^^^^^^^^ `std::time::Duration` cannot be formatted with the default formatter; try using `:?` instead if you are using a format string
|
= help: the trait `std::fmt::Display` is not implemented for `std::time::Duration`
= note: required because of the requirements on the impl of `std::fmt::Display` for `&std::time::Duration`
= note: required by `std::fmt::Display::fmt`