Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "axum-starter"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
authors = ["FrozenString<frozenstringstable@gmail.com>"]
description = "A help crate for simplify the code of starting a axum server"
Expand All @@ -24,7 +24,7 @@ members = ["./codegen/axum-starter-macro", "./examples/*"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
axum = "0.6"
axum-starter-macro = { version = "0.7.0" , path = "codegen/axum-starter-macro"}
axum-starter-macro = { version = "0.8.0" }
futures = "0.3"
http-body = "0.4"
hyper = { version = "0.14", features = ["server"] }
Expand Down
2 changes: 1 addition & 1 deletion codegen/axum-starter-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "axum-starter-macro"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
authors = ["FrozenString<frozenstringstable@gmail.com>"]
description = "A help crate for simplify the code of starting axum server "
Expand Down
42 changes: 41 additions & 1 deletion codegen/axum-starter-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,32 @@ pub fn derive_from_state_collector(input: proc_macro::TokenStream) -> proc_macro
/// named `SeaConn`, just using like `#[prepare(SeaConn)]`
///
/// if your function argument contain reference or other types witch need a lifetime, just add the lifetime to the macro arguments list,
/// like this
/// like this.
///
/// ```rust
/// #[prepare(Foo 'f)]
/// fn prepare_foo(foo_name: &'f String){
/// // do somethings
/// }
/// ```
/// Or,you can not provide any lifetime symbol, the macro will automatic find all needing lifetime places and giving a default symbol
///
/// ```rust
/// #[prepare(Foo)]
/// fn prepare_foo(foo_name: &String){
/// // do somethings
/// }
/// ```
///
/// Or only give lifetime symbol in macro input. The macro will auto replace `'_` into `'arg` if necessary
///
/// ```rust
/// #[prepare(Foo 'arg)]
/// fn prepare_foo(foo_name: &String){
/// // do somethings
/// }
/// ```
///
/// some times store `Future` on stack may cause ***Stack Overflow***, you can using `box` before generate name
/// make the return type became `Pin<Box<dyn Future>>`
///
Expand All @@ -160,6 +179,27 @@ pub fn derive_from_state_collector(input: proc_macro::TokenStream) -> proc_macro
/// // do something may take place large space
/// }
/// ```
///
/// if you want a `Prepare` return `Ready`, or in other word, a sync `Prepare`,you can use `sync` before the Ident.
/// note that `box` and `sync` cannot use in the same time
///
/// ```rust
/// #[prepare(sync Foo)]
/// fn prepare_foo(){
/// // do something not using `await`
/// }
/// ```
///
/// By default, the macro will not keep the origin function exist, if you want use that original function, using `origin`,
/// the `origin` is after the `box` or `sync`, but before the Ident
///
///```rust
/// #[prepare(sync origin Foo)]
/// fn prepare_foo(){
/// // do something not using `await`
/// }
/// ```
///```
#[proc_macro_attribute]
pub fn prepare(
attrs: proc_macro::TokenStream,
Expand Down
2 changes: 1 addition & 1 deletion src/prepare_behave/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{error::Error as StdError, future::IntoFuture, sync::Arc};
use futures::Future;

/// Prepare Task witch may return any kind of effect
pub trait Prepare<C: 'static> {
pub trait Prepare<C: 'static>: 'static {
/// the effect
type Effect: 'static;
/// prepare error
Expand Down