Update lib.rs

This commit is contained in:
fa-sharp
2026-03-19 22:11:28 -04:00
parent 004496b080
commit 57dd1da621

View File

@@ -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 {