axum-folder-router/examples/simple/main.rs
Tristan Druyen daf793eb06
Vastly improve testing
- simplify some examples
- add macrotest for expanding/snapshotting macro expansion & add tests
  - add workaround to enable referencing relative dirs from macrotest files
  - ensure workaround doesn't get built in release
- add trybuild for testing error messages & add tests
- fix indeterministic macro output
  - sort routes after collecting
  - use BTreeMap instead of HashMap to preserve insertion order
- fix compile_error syntax error
2025-04-15 13:33:40 +02:00

26 lines
753 B
Rust

use axum::Router;
use axum_folder_router::folder_router;
#[derive(Clone)]
struct AppState;
// Imports route.rs files & generates an ::into_router() fn
#[folder_router("./examples/simple/api", AppState)]
struct MyFolderRouter();
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create app state
let app_state = AppState;
// Use the init fn generated above
let folder_router: Router<AppState> = MyFolderRouter::into_router();
// Build the router and provide the state
let app: Router<()> = folder_router.with_state(app_state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
println!("Listening on http://{}", listener.local_addr()?);
axum::serve(listener, app).await?;
Ok(())
}