Skip to content

Struggling to work out HashMap implementation with custom type. #199

Answered by sunli829
ChillFish8 asked this question in Q&A
Discussion options

You must be logged in to vote

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>,
}

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@ChillFish8
Comment options

Comment options

You must be logged in to vote
1 reply
@ChillFish8
Comment options

Answer selected by ChillFish8
Comment options

You must be logged in to vote
1 reply
@ChillFish8
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants