Skip to content

dtolnay/erased-discriminant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Type-erased Discriminant

github crates.io docs.rs build status

This crate provides a Discriminant type that behaves like core::mem::Discriminant<T> but without the generic type parameter T. With this, we can build collections such as HashSet that contain discriminants from a mixture of different enum types.

use erased_discriminant::Discriminant;
use std::collections::HashSet;

enum Enum {
    A(i32),
    B,
}

enum DifferentEnum {
    A,
}

let mut set = HashSet::new();
set.insert(Discriminant::of(&Enum::A(99)));
set.insert(Discriminant::of(&Enum::B));
set.insert(Discriminant::of(&DifferentEnum::A));
assert_eq!(set.len(), 3);

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Type-erased core::mem::Discriminant<T>

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Contributors

Languages