#[derive(EnumSetType, Debug)] pubenum Enum1 {
A,
}
#[derive(EnumSetType, Debug)] pubenum SmallEnum {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
} #[derive(Clone, Copy, Debug, EnumSetType, Eq, PartialEq)] #[enumset(no_super_impls)] pubenum SmallEnumExplicitDerive {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
} #[derive(EnumSetType, Debug)] #[enumset(repr = "u128")] pubenum LargeEnum {
_00, _01, _02, _03, _04, _05, _06, _07,
_10, _11, _12, _13, _14, _15, _16, _17,
_20, _21, _22, _23, _24, _25, _26, _27,
_30, _31, _32, _33, _34, _35, _36, _37,
_40, _41, _42, _43, _44, _45, _46, _47,
_50, _51, _52, _53, _54, _55, _56, _57,
_60, _61, _62, _63, _64, _65, _66, _67,
_70, _71, _72, _73, _74, _75, _76, _77,
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
} #[derive(EnumSetType, Debug)] pubenum Enum8 {
A, B, C, D, E, F, G, H,
} #[derive(EnumSetType, Debug)] pubenum Enum128 {
A, B, C, D, E, F, G, H, _8, _9, _10, _11, _12, _13, _14, _15,
_16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31,
_32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47,
_48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63,
_64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79,
_80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95,
_96, _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, _108, _109,
_110, _111, _112, _113, _114, _115, _116, _117, _118, _119, _120, _121, _122,
_123, _124, _125, _126, _127,
} #[derive(EnumSetType, Debug)] pubenum SparseEnum {
A = 0xA, B = 20, C = 30, D = 40, E = 50, F = 60, G = 70, H = 80,
}
#[repr(u32)] #[derive(EnumSetType, Debug)] pubenum ReprEnum {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
} #[repr(u64)] #[derive(EnumSetType, Debug)] pubenum ReprEnum2 {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
} #[repr(isize)] #[derive(EnumSetType, Debug)] pubenum ReprEnum3 {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
} #[repr(C)] #[derive(EnumSetType, Debug)] pubenum ReprEnum4 {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
} #[derive(EnumSetType, Debug)] pubenum GiantEnum {
A = 100, B = 200, C = 300, D = 400, E = 500, F = 600, G = 700, H = 800,
} #[derive(EnumSetType, Debug)] #[enumset(repr = "array")] pubenum SmallArrayEnum {
A, B, C, D, E, F, G, H
} #[derive(EnumSetType, Debug)] #[enumset(repr = "array")] pubenum MarginalArrayEnumS2 {
A, B, C, D, E, F, G, H, Marginal = 64,
} #[derive(EnumSetType, Debug)] #[enumset(repr = "array")] pubenum MarginalArrayEnumS2H {
A = 64, B, C, D, E, F, G, H, Marginal = 127,
} #[derive(EnumSetType, Debug)] #[enumset(repr = "array")] pubenum MarginalArrayEnumS3 {
A, B, C, D, E, F, G, H, Marginal = 128,
}
macro_rules! test_variants {
($enum_name:ident $all_empty_test:ident $($variant:ident,)*) => { #[test] fn $all_empty_test() { let all = EnumSet::<$enum_name>::all(); let empty = EnumSet::<$enum_name>::empty();
$(
assert!(!empty.contains($enum_name::$variant));
assert!(all.contains($enum_name::$variant));
)*
}
}
}
test_variants! { SmallEnum small_enum_all_empty
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
}
test_variants! { SmallEnumExplicitDerive small_enum_explicit_derive_all_empty
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
}
test_variants! { LargeEnum large_enum_all_empty
_00, _01, _02, _03, _04, _05, _06, _07,
_10, _11, _12, _13, _14, _15, _16, _17,
_20, _21, _22, _23, _24, _25, _26, _27,
_30, _31, _32, _33, _34, _35, _36, _37,
_40, _41, _42, _43, _44, _45, _46, _47,
_50, _51, _52, _53, _54, _55, _56, _57,
_60, _61, _62, _63, _64, _65, _66, _67,
_70, _71, _72, _73, _74, _75, _76, _77,
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
}
test_variants! { SparseEnum sparse_enum_all_empty
A, B, C, D, E, F, G,
}
letmut set_2 = EnumSet::new(); let vec: Vec<_> = set.iter().collect(); for val in vec {
assert!(!set_2.contains(val));
set_2.insert(val);
}
assert_eq!(set, set_2);
letmut set_3 = EnumSet::new(); for val in set {
assert!(!set_3.contains(val));
set_3.insert(val);
}
assert_eq!(set, set_3);
letmut set_4 = EnumSet::new(); let vec: EnumSet<_> = set.into_iter().map(EnumSet::only).collect(); for val in vec {
assert!(!set_4.contains(val));
set_4.insert(val);
}
assert_eq!(set, set_4);
letmut set_5 = EnumSet::new(); let vec: EnumSet<_> = set.iter().collect(); for val in vec {
assert!(!set_5.contains(val));
set_5.insert(val);
}
assert_eq!(set, set_5);
}
#[test] fn empty_iter_test() { for _ in EnumSet::<$e>::new() {
panic!("should not happen");
}
}
#[test] fn iter_ordering_test() { let set_a = $e::A | $e::B | $e::E; let vec_a: Vec<_> = set_a.iter().collect();
assert_eq!(vec_a, &[$e::A, $e::B, $e::E]); let vec_a_rev: Vec<_> = set_a.iter().rev().collect();
assert_eq!(vec_a_rev, &[$e::E, $e::B, $e::A]);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.