You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::collections::HashMap;
use std::hash::Hash;
use serde_with;
use serde;
use serde::{Deserialize};
use serde_with::serde_as;
use serde_with::DurationSeconds;
#[serde_as]
#[derive(Deserialize)]
struct T {
#[serde_as(as = "HashMap<DurationSeconds, f64>")]
pub a: HashMap<std::time::Duration, f64>
}
But I'm getting a compiler error.
error[E0277]: the trait bound `HashMap<DurationSeconds, f64>: DeserializeAs<'_, _>` is not satisfied
--> src/main.rs:10:1
|
10 | #[serde_as]
| ^----------
| |
| _in this procedural macro expansion
| |
11 | | #[derive(Deserialize)]
| |____________________^ the trait `DeserializeAs<'_, _>` is not implemented for `HashMap<DurationSeconds, f64>`
|
= help: the following other types implement trait `DeserializeAs<'de, T>`:
<HashMap<KAs, VAs> as DeserializeAs<'de, BTreeSet<(K, V)>>>
<HashMap<KAs, VAs> as DeserializeAs<'de, HashSet<(K, V), S>>>
<HashMap<KAs, VAs> as DeserializeAs<'de, BinaryHeap<(K, V)>>>
<HashMap<KAs, VAs> as DeserializeAs<'de, Box<[(K, V)]>>>
<HashMap<KAs, VAs> as DeserializeAs<'de, LinkedList<(K, V)>>>
<HashMap<KAs, VAs> as DeserializeAs<'de, Vec<(K, V)>>>
<HashMap<KAs, VAs> as DeserializeAs<'de, VecDeque<(K, V)>>>
<HashMap<KAs, VAs> as DeserializeAs<'de, std::option::Option<(K, V)>>>
and 2 others
note: required by a bound in `serde_with::de::<impl As<T>>::deserialize`
--> /Users/rollokonig-brock/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_with-3.4.0/src/de/mod.rs:153:12
|
151 | pub fn deserialize<'de, D, I>(deserializer: D) -> Result<I, D::Error>
| ----------- required by a bound in this associated function
152 | where
153 | T: DeserializeAs<'de, I>,
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `serde_with::de::<impl As<T>>::deserialize`
= note: this error originates in the attribute macro `serde_as` (in Nightly builds, run with -Z macro-backtrace for more info)
I'm assuming I'm misunderstanding how to use this. Any pointers?
The text was updated successfully, but these errors were encountered:
rollo-b2c2
changed the title
Using DurationSeconds in a hashmap
[usage question] Using DurationSeconds in a hashmap
Nov 7, 2023
The problem is with the f64 not the DurationSeconds. There is no DeserializeAs implementation for f64 that matches here. That is why you get the error. For the f64 you want to use the default Deserialize implementation. You do this by using _. That is an unfortunate papercut, see #202.
Hey this is a usage question,
Trying to do this?
But I'm getting a compiler error.
I'm assuming I'm misunderstanding how to use this. Any pointers?
The text was updated successfully, but these errors were encountered: