axum-core-state

Fixes Axum 0.7/0.8 shared state wiring for handlers using Router::with_state and FromRef.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-core-state
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-core-state
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-core/axum-core-state
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-core-state

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents common Axum state-wiring failures where handlers extract shared state but the router never provides it, or where application-wide resources are injected via Extension and silently fail at runtime.

Core Features & Use Cases

  • Compile-time correct state wiring: Use Router<S> with Router::with_state to make only Router<()> serveable, catching missing wiring before deployment.
  • State extraction and substate composition: Use State<S> plus FromRef and derive(FromRef) to pull per-handler substates from a larger AppState.
  • Performance and correctness guardrails: Ensure state is Clone, wrap heavy immutable data in Arc, and use tokio::sync::Mutex (or scope std::sync::Mutex) to avoid !Send futures caused by holding a mutex guard across .await.

Quick Start

Ask Claude to show how to restructure your Axum router to provide AppState via Router::with_state and extract only the needed fields with State and derive(FromRef), fixing both the Extension 500 trap and any Handler is not satisfied errors.

Frequently Asked Questions about axum-core-state

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my Axum handler return a 500 error when extracting shared application state?

Axum shared application state extraction returns 500 errors when resources are injected via Extension instead of Router::with_state. Using Router<S> with Router::with_state ensures only Router<()> is serveable, catching missing state wiring at compile time.

How do I use FromRef to extract substates from a larger AppState in Axum?

Use derive(FromRef) on your AppState struct to generate per-handler substate implementations. State<S> extractors then pull only the needed fields from the larger application state, keeping handlers decoupled from the full state tree.

Does holding a std::sync::Mutex guard across an await point break Axum handler futures?

Holding a std::sync::Mutex guard across .await makes Axum handler futures !Send, causing runtime panics. Use tokio::sync::Mutex for async scopes, or scope std::sync::Mutex guards to drop before any .await calls to maintain Send requirements.

What's the best way to share heavy immutable data across Axum handlers?

Wrap heavy immutable data in Arc and ensure your Axum state is Clone. This allows Router::with_state to safely clone the state reference for each handler without deep copying the underlying data.

How do I fix the Handler is not satisfied error when wiring an Axum router?

The Handler is not satisfied error occurs when Axum router state types mismatch handler extractors. Restructure your router to provide AppState via Router::with_state and use State<S> extractors to resolve the type mismatch.

When should I use Extension instead of State for sharing data in Axum?

Avoid Extension for sharing application state in Axum because it silently fails at runtime if missing. Use Router::with_state with State<S> extractors instead to guarantee state availability and catch wiring failures at compile time.