forgot docs

This commit is contained in:
davidon-top 2023-10-06 22:10:33 +02:00
parent 1e309909eb
commit a87fcfb937
3 changed files with 23 additions and 3 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "binf" name = "binf"
version = "1.0.0-rc1" version = "1.0.0"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
description = "A crate that adds utilities for dealing with binary flags" 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/" documentation = "https://docs.rs/binf/"
[dependencies] [dependencies]
binf_macros = { path = "macros", version = "0.1.0" } binf_macros = { path = "macros", version = "0.1.1" }

View file

@ -1,6 +1,6 @@
[package] [package]
name = "binf_macros" name = "binf_macros"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
description = "A crate that adds utilities for dealing with binary flags" description = "A crate that adds utilities for dealing with binary flags"

View file

@ -1,5 +1,25 @@
use proc_macro::TokenStream; 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] #[proc_macro_attribute]
pub fn bitflag(_attr: TokenStream, input: TokenStream) -> TokenStream { pub fn bitflag(_attr: TokenStream, input: TokenStream) -> TokenStream {
let structdef: syn::ItemStruct = syn::parse_macro_input!(input as syn::ItemStruct); let structdef: syn::ItemStruct = syn::parse_macro_input!(input as syn::ItemStruct);