Cannot use `env` together with `deserialize_with`
Dav1dde opened this issue · 2 comments
Dav1dde commented
Using env
and deserialize_with
together fails with the following error(s):
error[E0277]: the trait bound `Url: Deserialize<'_>` is not satisfied
--> yggdrasil/src/config.rs:3:24
|
3 | #[derive(Debug, Clone, Config)]
| ^^^^^^ the trait `Deserialize<'_>` is not implemented for `Url`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a Path
&'a [u8]
&'a str
()
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
and 1350 others
= note: required because of the requirements on the impl of `Deserialize<'_>` for `std::option::Option<Url>`
note: required by a bound in `confique::internal::from_env`
--> /home/dav1d/.cargo/registry/src/github.com-1ecc6299db9ec823/confique-0.1.3/src/internal.rs:35:25
|
35 | pub fn from_env<'de, T: serde::Deserialize<'de>>(key: &str, field: &str) -> Result<T, Error> {
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `confique::internal::from_env`
= note: this error originates in the derive macro `Config` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `yggdrasil` due to previous error
e.g.
#[derive(Debug, Clone, Config)]
pub struct Settings {
#[config(env = "RANCHER_SERVER", deserialize_with = utils::url)]
pub rancher_server: url::Url,
}
mod utils {
use serde::Deserializer;
pub fn url<'de, D>(deserializer: D) -> Result<url::Url, D::Error> where D: Deserializer<'de> {
todo!()
}
}
LukasKalbertodt commented
Hi there and thank you for the clear bug report! This was indeed just an oversight on my side. I fixed it in the commit referenced above. I will still work on some other stuff before releasing this, but that should happen in the next few hours, at most days.
Edit: I did a woopsie, amended that commit and force pushed. So the commit closing this issue is not valid anymore. See eb03488 instead.
LukasKalbertodt commented
And the fix is now published as 0.1.4