Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General hashes-like relation #43

Open
bluss opened this issue Oct 13, 2017 · 1 comment
Open

General hashes-like relation #43

bluss opened this issue Oct 13, 2017 · 1 comment

Comments

@bluss
Copy link
Member

bluss commented Oct 13, 2017

  • Example: Hash table that is keyed by newtyped strings and lookup is case-insensitive.
  • Use case: Want to lookup using &str.
@bluss bluss changed the title Generalized hashes-like relation General hashes-like relation Oct 13, 2017
@RReverser
Copy link

FWIW I'm currently doing this with newtype, which generally works pretty well:

pub struct ProductionSetItem(Production);

impl Deref for ProductionSetItem {
    type Target = Production;

    fn deref(&self) -> &Production {
        &self.0
    }
}

impl Borrow<str> for ProductionSetItem {
    fn borrow(&self) -> &str {
        &self.name
    }
}

impl PartialEq for ProductionSetItem {
    fn eq(&self, other: &Self) -> bool {
        self.name == other.name
    }
}

impl Eq for ProductionSetItem {}

impl Hash for ProductionSetItem {
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.name.hash(state)
    }
}

Maybe it's worth just providing some macro to generate them automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants