1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! [`Serve`] — extension trait that lets you start an `axum::Router`
//! with a one-liner.
//!
//! ```no_run
//! use vespera::Serve;
//!
//! #[tokio::main]
//! async fn main() -> std::io::Result<()> {
//! vespera::axum::Router::new().serve("0.0.0.0:3000").await
//! }
//! ```
//!
//! Pairs naturally with the [`vespera!`](vespera_macro::vespera) macro
//! (marked `ignore` because the macro scans the caller's `src/routes/`
//! at compile time, which doesn't exist in a doctest sandbox):
//!
//! ```ignore
//! vespera!(title = "My API").serve("0.0.0.0:3000").await
//! ```
//!
//! Equivalent to:
//!
//! ```ignore
//! let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
//! axum::serve(listener, app).await?;
//! ```
use io;
use ToSocketAddrs;
/// Extension trait that adds a one-liner [`Serve::serve`] method to
/// any [`axum::Router`].
/// Lets a **stateless** merged app from `vespera!(merge = [...])` —
/// which returns a [`crate::VesperaRouter<()>`] rather than a plain
/// `axum::Router` — start with the same one-liner, without the user
/// having to remember the `.with_state(())` finalizer first:
///
/// ```ignore
/// vespera!(merge = [other::App]).serve("0.0.0.0:3000").await
/// ```
///
/// Finalizing with `()` runs the deferred child-router merge and layer
/// replay (see [`crate::VesperaRouter::with_state`]) before binding, so
/// merged routes and layers are present when the listener starts.