boson_axum/state.rs
1//! Shared Axum state for Boson handlers.
2
3use std::sync::Arc;
4
5use boson_runtime::Boson;
6
7/// Extractable state holding a [`Boson`] runtime.
8///
9/// Construct with [`BosonState::new`] after [`BosonBuilder::build`](boson_runtime::BosonBuilder::build)
10/// and inject via [`FromRef`](axum::extract::FromRef) (see the [crate example](crate#example)).
11#[derive(Clone)]
12pub struct BosonState {
13 /// Boson runtime for admin and enqueue operations.
14 pub boson: Arc<Boson>,
15}
16
17impl BosonState {
18 /// Create state from a shared Boson instance.
19 ///
20 /// ```rust,no_run
21 /// use std::sync::Arc;
22 /// use boson_axum::BosonState;
23 /// use boson_runtime::Boson;
24 ///
25 /// # fn demo(boson: Boson) {
26 /// let state = BosonState::new(Arc::new(boson));
27 /// # let _ = state;
28 /// # }
29 /// ```
30 #[must_use]
31 pub const fn new(boson: Arc<Boson>) -> Self {
32 Self { boson }
33 }
34}