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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! ## Extractor
//!
//! Re-usable pieces of code to extract data from a signal or the application
//! state.
//!
//! See [`FromRequest`] for more details.
//!
//! ## Examples
//!
//! ```rust,no_run
//! use std::sync::Arc;
//!
//! use rinf::DartSignal;
//! use rinf_router::{Router, State};
//! use serde::Deserialize;
//!
//! // Define your application state
//! #[derive(Clone)]
//! struct AppState {
//! some_number: Arc<i32>,
//! }
//!
//! // ..And your signals
//! #[derive(Deserialize, DartSignal)]
//! struct MyMessage(String);
//!
//! // Use `State` extractor in your handler
//! async fn handler(State(state): State<AppState>, message: MyMessage) {
//! println!("Message: {}, State: {}", message.0, state.some_number);
//! }
//!
//! #[tokio::main]
//! async fn main() {
//! // Register handler with router
//! let app_state = AppState {
//! some_number: Arc::new(42),
//! };
//!
//! Router::new()
//! .route(handler)
//! .with_state(app_state)
//! .run()
//! .await;
//! }
//! ```
//!
//! Now your handler holds a state
use async_trait;
/// An asynchronous trait for extracting data from [`T`] and the state: [`S`].
///
/// This trait allows implementing types to define how they should be
/// constructed from incoming RINF signals. It is used to provide a consistent
/// way to access request data within handlers.
/// An extractor type for accessing the shared application state within
/// handlers.
///
/// This is the main mechanism to inject application context state into your
/// handlers.
;