From ad0462d2c3cf9602f4457219834203480e9d57e1 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Tue, 28 Mar 2023 16:34:35 +0200 Subject: [PATCH 1/3] update README --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dd6db44..50e2433 100644 --- a/README.md +++ b/README.md @@ -86,14 +86,14 @@ const _: () = { impl ::enum_tag::EnumTag for Foo { type Tag = FooTag; - fn tag(&self) -> Self::Tag { + fn tag(&self) -> ::Tag { match self { - Self::A { .. } => Self::Tag::A, - Self::B { .. } => Self::Tag::B, - Self::C { .. } => Self::Tag::C, - Self::D { .. } => Self::Tag::D, - Self::E { .. } => Self::Tag::E, - Self::F { .. } => Self::Tag::F, + Self::A { .. } => ::Tag::A, + Self::B { .. } => ::Tag::B, + Self::C { .. } => ::Tag::C, + Self::D { .. } => ::Tag::D, + Self::E { .. } => ::Tag::E, + Self::F { .. } => ::Tag::F, } } } From 67254da3ac51258a93dbf9df6f09f320d7399216 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Tue, 28 Mar 2023 16:34:43 +0200 Subject: [PATCH 2/3] extend proc. macro docs --- macro/src/lib.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/macro/src/lib.rs b/macro/src/lib.rs index 2dec94d..6eaa723 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -17,7 +17,7 @@ mod derive; /// # Example /// /// ``` -/// use ::enum_tag::EnumTag; +/// use enum_tag::EnumTag; /// /// #[derive(EnumTag)] /// #[repr(u8)] // Rust needs this for `B = 42` @@ -42,6 +42,56 @@ mod derive; /// /// assert_eq!(FooTag::B as u8, 42); /// ``` +/// +/// The above `#[derive(EnumTag)]` proc. macro will expand to roughly the following Rust code: +/// +/// ``` +/// # #[repr(u8)] // Rust needs this for `B = 42` +/// # enum Foo { +/// # A, +/// # B = 42, +/// # C(i32), +/// # D(i32, i64), +/// # E { a: i32 }, +/// # F { a: i32, b: i64 }, +/// # } +/// # +/// const _: () = { +/// #[derive( +/// ::core::fmt::Debug, +/// ::core::clone::Clone, +/// ::core::marker::Copy, +/// ::core::cmp::PartialEq, +/// ::core::cmp::Eq, +/// ::core::cmp::PartialOrd, +/// ::core::cmp::Ord, +/// ::core::hash::Hash, +/// )] +/// pub enum FooTag { +/// A, +/// B = 42, +/// C, +/// D, +/// E, +/// F, +/// } +/// +/// impl ::enum_tag::EnumTag for Foo { +/// type Tag = FooTag; +/// +/// fn tag(&self) -> ::Tag { +/// match self { +/// Self::A { .. } => ::Tag::A, +/// Self::B { .. } => ::Tag::B, +/// Self::C { .. } => ::Tag::C, +/// Self::D { .. } => ::Tag::D, +/// Self::E { .. } => ::Tag::E, +/// Self::F { .. } => ::Tag::F, +/// } +/// } +/// } +/// }; +/// ``` #[proc_macro_derive(EnumTag)] pub fn enum_tag(input: TokenStream) -> TokenStream { derive::enum_tag(parse_macro_input!(input as DeriveInput)).into() From 6c0e6826e2689443546bdadf7f8438e1a675ca6b Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Tue, 28 Mar 2023 16:36:03 +0200 Subject: [PATCH 3/3] apply rustfmt --- macro/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/macro/src/lib.rs b/macro/src/lib.rs index 6eaa723..05d8862 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -42,9 +42,9 @@ mod derive; /// /// assert_eq!(FooTag::B as u8, 42); /// ``` -/// +/// /// The above `#[derive(EnumTag)]` proc. macro will expand to roughly the following Rust code: -/// +/// /// ``` /// # #[repr(u8)] // Rust needs this for `B = 42` /// # enum Foo { @@ -75,10 +75,10 @@ mod derive; /// E, /// F, /// } -/// +/// /// impl ::enum_tag::EnumTag for Foo { /// type Tag = FooTag; -/// +/// /// fn tag(&self) -> ::Tag { /// match self { /// Self::A { .. } => ::Tag::A,