Struggling to work out HashMap implementation with custom type. #199
-
We have a custom type in this case If we have a field with say this example struct: #[derive(Object)]
struct Foo {
bar: JsSafeBigInt,
} It works (All the required traits are implemented for it. But if we make this a map e.g. #[derive(Object)]
struct Foo {
bar: HashMap<JsSafeBigInt, bool>,
} we get the following error:
Which is slightly confusing. And im not entirely sure how to fix this. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
You need to implement the following traits for impl FromStr for JsSafeBigInt {
type Err: ParseJsSafeBigIntError;
....
}
impl Display for ParseJsSafeBigIntError {
}
impl Display for JsSafeBigInt {
} |
Beta Was this translation helpful? Give feedback.
-
It works. 😁 #[derive(Debug, Eq, PartialEq, Hash)]
struct JsSafeBigInt(i64);
impl FromStr for JsSafeBigInt {
type Err = std::num::ParseIntError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse()
}
}
impl Display for JsSafeBigInt {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
#[derive(Object)]
struct Foo {
bar: HashMap<JsSafeBigInt, bool>,
} |
Beta Was this translation helpful? Give feedback.
-
I can't reproduce this error message:
On
What rust version are you using? 🙂 |
Beta Was this translation helpful? Give feedback.
It works. 😁