diff --git a/Cargo.lock b/Cargo.lock index 6d00e5e..02b05ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,6 @@ dependencies = [ name = "bok-macro" version = "0.1.0" dependencies = [ - "bok", "proc-macro2", "quote", "syn", diff --git a/bok-macro/Cargo.toml b/bok-macro/Cargo.toml index b1479a0..6f9c2d1 100644 --- a/bok-macro/Cargo.toml +++ b/bok-macro/Cargo.toml @@ -15,5 +15,4 @@ proc-macro = true [dependencies] syn = { version = "2.0", features = [ "full" ] } quote = { version = "1.0" } -bok = { path = "../bok" } proc-macro2 = "1.0" diff --git a/bok-macro/src/lib.rs b/bok-macro/src/lib.rs index d6028af..56affd3 100644 --- a/bok-macro/src/lib.rs +++ b/bok-macro/src/lib.rs @@ -17,15 +17,12 @@ use ::proc_macro::TokenStream; use ::quote::quote; -use ::syn::{ - parse::{ParseBuffer, ParseStream, Parser}, - parse_macro_input, DeriveInput, -}; +use ::syn::{parse::Parser, parse_macro_input, DeriveInput}; -/// Use as #[repository(MyBaseRepo)] +/// Use as #[::bok::repository(MyBaseRepo)] /// Will setup a `base` field that is the given base repo /// -/// e.g.: `#[repository(::bok::RepositoryEmpty)]` +/// e.g.: `#[::bok::repository(::bok::RepositoryEmpty)]` #[proc_macro_attribute] pub fn repository(attrs: TokenStream, input: TokenStream) -> TokenStream { let mut ast = parse_macro_input!(input as DeriveInput); @@ -44,6 +41,7 @@ pub fn repository(attrs: TokenStream, input: TokenStream) -> TokenStream { } quote! { + #[derive(::bok::Repository)] #ast } .into() @@ -52,7 +50,9 @@ pub fn repository(attrs: TokenStream, input: TokenStream) -> TokenStream { } } -/// Use as #[derive(Repository)] +/// Unless you know what you are doing, use `#[::bok::repository(MyBaseRepo)]` instead +/// +/// Use as #[derive(::bok::Repository)] /// adds extension capabilities to a repo #[proc_macro_derive(Repository)] pub fn derive_repository(input: TokenStream) -> TokenStream { @@ -94,14 +94,14 @@ pub fn derive_repository(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } -/// Use on a function as #[to_code] +/// Use on a function as `#[::bok::to_code]` /// will create a new function, same name with `_code` that /// returns the ::proc_macro2::TokenStream of the function /// /// e.g.: /// ``` /// impl MyPackage { -/// #[::bok_macro::to_code] +/// #[::bok::to_code] /// fn build() { /// ... /// } @@ -177,10 +177,10 @@ pub fn to_code(_attrs: TokenStream, input: TokenStream) -> TokenStream { */ } -/// Use as #[package(MyBasePackage)] +/// Use as #[::bok::package(MyBasePackage)] /// Will setup a `base` field that is the given base package /// -/// e.g.: `#[package(::bok::PkgEmpty)]` +/// e.g.: `#[::bok::package(::bok::PkgEmpty)]` #[proc_macro_attribute] pub fn package(attrs: TokenStream, input: TokenStream) -> TokenStream { let mut ast = parse_macro_input!(input as DeriveInput); @@ -199,6 +199,7 @@ pub fn package(attrs: TokenStream, input: TokenStream) -> TokenStream { } quote! { + #[derive(::bok::Package)] #ast } .into() @@ -207,7 +208,9 @@ pub fn package(attrs: TokenStream, input: TokenStream) -> TokenStream { } } -/// #[derive(Package)] +/// Unless you know what you are doing, use `#[::bok::package(MyBasePackage)]` instead +/// +/// #[derive(::bok::Package)] /// adds: /// * Builder pattern to a package /// * deref for builder towards `.base` @@ -382,7 +385,7 @@ pub fn derive_package(input: TokenStream) -> TokenStream { ->::core::fmt::Result { // FIXME: this sounds convoluted. - // first we make everything into a string, then we + // first we turn everything into a string, then we // parse the string into tokenstream again to format it // reason: the `prettyplease` works on `::syn::File` // and I can't find an easy translation @@ -398,7 +401,7 @@ pub fn derive_package(input: TokenStream) -> TokenStream { use ::core::fmt::Write; write!(out, - "#[::bok_macro::to_code]\n\ + "#[::bok::to_code]\n\ fn {}(&self) -> Result<(), ()> {{\n{}\n}}\n", name, fn_str) @@ -407,7 +410,6 @@ pub fn derive_package(input: TokenStream) -> TokenStream { } }; - // from the Pkg trait use ::core::fmt::Write; let pkg_empty = ::bok::PkgEmpty{}; diff --git a/bok-utils/src/pkgs/mod.rs b/bok-utils/src/pkgs/mod.rs index bacfb8f..9bf8f73 100644 --- a/bok-utils/src/pkgs/mod.rs +++ b/bok-utils/src/pkgs/mod.rs @@ -31,7 +31,7 @@ bok::moduse! { /// Base repository with some packages /// #[::bok_macro::repository(::bok::RepositoryEmpty)] -#[derive(::bok_macro::Repository, ::std::default::Default)] +#[derive(::std::default::Default)] pub struct Pkgs1 {} // Add some packages to the repository @@ -47,7 +47,7 @@ bok::repo_packages! { /// This repository extends and changes Pkgs1 /// #[::bok_macro::repository(Pkgs1)] -#[derive(::bok_macro::Repository, ::std::default::Default)] +#[derive(::std::default::Default)] pub struct Pkgs2 {} // add a third package with `::default()` values diff --git a/bok-utils/src/pkgs/one.rs b/bok-utils/src/pkgs/one.rs index 8b8efa4..cff9ffd 100644 --- a/bok-utils/src/pkgs/one.rs +++ b/bok-utils/src/pkgs/one.rs @@ -18,7 +18,6 @@ /// Example package /// Automatically implements `.builder().my_attr(42).build()` pattern #[::bok_macro::package(::bok::PkgEmpty)] -#[derive(::bok_macro::Package)] pub struct One { pub my_attr: u32, } diff --git a/bok-utils/src/pkgs/three.rs b/bok-utils/src/pkgs/three.rs index bf65bee..c30bad6 100644 --- a/bok-utils/src/pkgs/three.rs +++ b/bok-utils/src/pkgs/three.rs @@ -18,7 +18,6 @@ /// Example package /// Automatically implements `.builder().my_attr(42).build()` pattern #[::bok_macro::package(::bok::PkgEmpty)] -#[derive(::bok_macro::Package)] pub struct Three { pub my_attr: u32, } diff --git a/bok-utils/src/pkgs/two.rs b/bok-utils/src/pkgs/two.rs index df6ca59..3126a32 100644 --- a/bok-utils/src/pkgs/two.rs +++ b/bok-utils/src/pkgs/two.rs @@ -18,7 +18,6 @@ /// Example package /// Automatically implements `.builder().my_attr(42).build()` pattern #[::bok_macro::package(::bok::PkgEmpty)] -#[derive(::bok_macro::Package)] pub struct Two { pub my_attr: u32, } diff --git a/bok/Cargo.toml b/bok/Cargo.toml index df25687..fda9f43 100644 --- a/bok/Cargo.toml +++ b/bok/Cargo.toml @@ -18,6 +18,4 @@ paste = "1.0" bitflags = "2.4" proc-macro2 = "1.0" quote = "1.0" - -[dev-dependencies] bok-macro = { path="../bok-macro" } diff --git a/bok/src/lib.rs b/bok/src/lib.rs index b4cdb34..b33b77b 100644 --- a/bok/src/lib.rs +++ b/bok/src/lib.rs @@ -15,6 +15,8 @@ * limitations under the License. */ +pub use ::bok_macro::{package, repository, to_code, Package, Repository}; + //use ::std::any::Any; // Package stuff