Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[macro_export]
- macro_rules! assert_variant {
- ($e:path: $($v:ident),+ $(,)?) => {
- #[allow(unused_imports)]
- const _: fn() = || {
- use $e as AnEnum;
- $(
- use AnEnum::$v as _;
- )+
- };
- };
- }
- pub mod tests {
- #[allow(dead_code)]
- pub enum Thing {
- A,
- B { x: () },
- C(()),
- AnEnum,
- }
- #[test]
- fn should_compile() {
- assert_variant!(Thing: A);
- assert_variant!(Thing: B);
- assert_variant!(Thing: C);
- assert_variant!(self::Thing: AnEnum, A, B, C);
- }
- /// # Single missing variant
- ///
- /// ```fail_compile
- /// use playground::assert_variant;
- /// use playground::tests::Thing;
- ///
- /// assert_variant!(Thing: D);
- /// ```
- ///
- /// # Multiple missing variants
- ///
- /// ```fail_compile
- /// use playground::assert_variant;
- /// use playground::tests::Thing;
- ///
- /// assert_variant!(Thing: D, E, F);
- /// ```
- ///
- /// # Multiple missing variants with a single existing variant.
- ///
- /// ```fail_compile
- /// use playground::assert_variant;
- /// use playground::tests::Thing;
- ///
- /// assert_variant!(Thing: A, D, E, F);
- /// ```
- ///
- /// # Missing variant with path to Enum
- ///
- /// ```fail_compile
- /// use playground::assert_variant;
- /// use playground::tests::Thing;
- ///
- /// assert_variant!(playground::tests::Thing: D, AnEnum);
- /// ```
- #[allow(dead_code)]
- fn fail_compile() {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement