Skip to content

Commit

Permalink
@2024-03-03 15:36+9:00
Browse files Browse the repository at this point in the history
  • Loading branch information
kanarus committed Mar 3, 2024
1 parent 38cdc48 commit 6a8fe09
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions ohkami/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod __rt__ {

mod request;
pub use request::{Request, Method, FromRequestError, FromRequest, FromParam, Memory};
pub use ::ohkami_macros::FromRequest;

mod response;
pub use response::{Response, Status, IntoResponse};
Expand Down
19 changes: 16 additions & 3 deletions ohkami_macros/src/from_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
use proc_macro2::TokenStream;
use syn::{Error, Result};
use proc_macro2::{Span, TokenStream};
use syn::{Error, ItemStruct, Result};

pub(super) fn derive_from_request(target: TokenStream) -> Result<TokenStream> {

let s: ItemStruct = syn::parse2(target)?;

if s.generics.lifetimes().count() >= 2 {
return Err(Error::new(Span::call_site(), "`#[derive(FromRequest)]` doesn't support multiple lifetimes!"))
}

if s.semi_token.is_none() {/* struct S { 〜 } */


} else {/* struct T(); */

}

todo!()
}
22 changes: 22 additions & 0 deletions ohkami_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,28 @@ pub fn ResponseBody(format: proc_macro::TokenStream, data: proc_macro::TokenStre
}


/// # `#[derive(FromRequest)]`
///
/// Automatically impl `FromRequest` for a struct composed of
/// `FromRequest` types
///
/// <br>
///
/// *example.rs*
/// ```ignore
/// use ohkami::FromRequest;
/// use sqlx::PgPool;
///
/// #[derive(FromRequest)]
/// struct MyItems1<'req> {
/// db: ohkami::Memory<'req, PgPool>,
/// }
///
/// #[derive(FromRequest)]
/// struct MyItems2(
/// MyItems<'req>,
/// );
/// ```
#[proc_macro_derive(FromRequest)]
pub fn derive_from_request(target: proc_macro::TokenStream) -> proc_macro::TokenStream {
from_request::derive_from_request(target.into())
Expand Down

0 comments on commit 6a8fe09

Please sign in to comment.