From a87fcfb93758c42b72afdce5f7766046fc0609c1 Mon Sep 17 00:00:00 2001 From: davidon-top Date: Fri, 6 Oct 2023 22:10:33 +0200 Subject: [PATCH] forgot docs --- Cargo.toml | 4 ++-- macros/Cargo.toml | 2 +- macros/src/lib.rs | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b0321c..758954f 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "binf" -version = "1.0.0-rc1" +version = "1.0.0" edition = "2021" license = "MIT" description = "A crate that adds utilities for dealing with binary flags" @@ -10,4 +10,4 @@ repository = "https://github.com/D0A1V2I3D/binf" documentation = "https://docs.rs/binf/" [dependencies] -binf_macros = { path = "macros", version = "0.1.0" } +binf_macros = { path = "macros", version = "0.1.1" } diff --git a/macros/Cargo.toml b/macros/Cargo.toml index b81251c..7639ff3 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "binf_macros" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MIT" description = "A crate that adds utilities for dealing with binary flags" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 2677365..66f92ac 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,5 +1,25 @@ use proc_macro::TokenStream; +/// Attribute proc macro that turns a struct into a bitflag +/// The underlying type of the bitflag is chosen based on the number of fields in the struct +/// usage: +/// ```rust +/// #[bitflag] +/// pub struct MyBitflag { +/// a: bool, +/// b: bool, +/// c: bool, +/// } +/// +/// fn main() { +/// let mut flag = MyBitflag::new(0); +/// flag.set_a(true); +/// let a = flag.a(); +/// } +/// ``` +/// You should also be able to add derive macros on the struct because the macro copies all attributes to the new struct +/// so you should be able to derive Serialize for example its just that in serialized data you will see the underlying type (unsigned number) +/// you can also call functions from BitFlag trait beacause the new struct implements deref and deref_mut to the underlying type #[proc_macro_attribute] pub fn bitflag(_attr: TokenStream, input: TokenStream) -> TokenStream { let structdef: syn::ItemStruct = syn::parse_macro_input!(input as syn::ItemStruct);