Compare commits
1 Commits
004496b080
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57dd1da621 |
@@ -20,12 +20,14 @@ use syn::{Data, DeriveInput, Fields, parse_macro_input};
|
|||||||
/// pool: Pool,
|
/// pool: Pool,
|
||||||
/// db: Db,
|
/// db: Db,
|
||||||
/// }
|
/// }
|
||||||
|
/// // To wrap the whole state in `Arc`, implement `TryFrom<TypeMap>` for `Arc<AppState>`:
|
||||||
|
/// impl TryFrom<TypeMap> for Arc<AppState> {
|
||||||
|
/// type Error = anyhow::Error;
|
||||||
///
|
///
|
||||||
/// // Plain state — axum will clone the whole struct on each request:
|
/// fn try_from(map: TypeMap) -> Result<Self, Self::Error> {
|
||||||
/// App::<AppState>::new()
|
/// Ok(Self(Arc::new(AppState::try_from(map)?)))
|
||||||
///
|
/// }
|
||||||
/// // Or wrap in Arc yourself for cheap clones:
|
/// }
|
||||||
/// App::<Arc<AppState>>::new()
|
|
||||||
/// ```
|
/// ```
|
||||||
#[proc_macro_derive(AppState)]
|
#[proc_macro_derive(AppState)]
|
||||||
pub fn derive_app_state(input: TokenStream) -> TokenStream {
|
pub fn derive_app_state(input: TokenStream) -> TokenStream {
|
||||||
|
|||||||
Reference in New Issue
Block a user