diff --git a/Cargo.toml b/Cargo.toml index 05f02f3..d935827 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ bytes = "1.8.0" http-body-util = "0.1.2" sqlx = {version = "0.8.1", features = ["sqlite", "sqlx-macros", "runtime-tokio"]} daemonize = {version = "0.5.0", optional = true} +aweblib_macros = {path = "aweblib_macros" } [dev-dependencies] futures = "0.3.31" \ No newline at end of file diff --git a/aweblib_macros/.gitignore b/aweblib_macros/.gitignore new file mode 100644 index 0000000..36e2917 --- /dev/null +++ b/aweblib_macros/.gitignore @@ -0,0 +1,2 @@ +Cargo.lock +/target \ No newline at end of file diff --git a/aweblib_macros/Cargo.toml b/aweblib_macros/Cargo.toml new file mode 100644 index 0000000..2f61231 --- /dev/null +++ b/aweblib_macros/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "aweblib_macros" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] +syn = "2.0.90" +quote = "1.0.37" \ No newline at end of file diff --git a/aweblib_macros/src/lib.rs b/aweblib_macros/src/lib.rs new file mode 100644 index 0000000..60dfeae --- /dev/null +++ b/aweblib_macros/src/lib.rs @@ -0,0 +1,28 @@ +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, Data, DataStruct}; + +#[proc_macro_derive(Getter)] +pub fn getter(item: TokenStream) -> TokenStream { + let input = parse_macro_input!(item as syn::DeriveInput); + let ident = input.ident; + let mut quote = quote! { + println!("Test"); + }; + if let Data::Struct(DataStruct { fields, .. }) = input.data { + for field in fields { + let name = field.ident.unwrap(); + quote.extend(quote! { + println!("{}",stringify!(#name)); + }) + } + } + quote!( + impl #ident { + fn get() { + #quote + } + } + ) + .into() +} diff --git a/src/lib.rs b/src/lib.rs index 30bce55..1cc5338 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ mod routing; mod server; mod settings; +pub use aweblib_macros::Getter; + pub struct SimpleHttpServer { server: Server, } @@ -34,3 +36,18 @@ impl SimpleHttpServer { self.server.run() } } + +#[cfg(test)] +mod test { + use aweblib_macros::Getter; + #[derive(Getter)] + pub struct Test { + one: u8, + two: String, + } + + #[test] + fn test() { + Test::get(); + } +} diff --git a/src/renderer.rs b/src/renderer.rs index c8112fb..9e986b6 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -13,7 +13,9 @@ pub(crate) fn get_static(file: &String) -> Response
{ } } -pub(crate) fn get_rendered() {} +pub(crate) fn get_rendered(file: &String) -> Response { + todo!() +} fn read_static(file: &String) -> Result