azalea_service/
lib.rs

1//! # azalea-service
2//!
3//! Service traits used by Azalea
4
5mod handler;
6pub use handler::*;
7
8mod status;
9pub use status::*;
10
11pub mod error;
12
13use tokio::sync::broadcast;
14
15/// Trait that Azalea services must implement
16pub trait Service
17where
18    Self: Sized + Send + 'static,
19{
20    type Init: Clone + Send;
21    type Input: Send;
22    type Event: Send;
23    type Output: Clone + 'static + Send;
24    const DISABLE_EVENTS: bool = false;
25    const LOCAL: bool = false;
26
27    fn new(
28        init: Self::Init,
29        input_sender: flume::Sender<Self::Input>,
30        output_sender: broadcast::Sender<Self::Output>,
31    ) -> impl std::future::Future<Output = Self> + Send;
32
33    fn handler(init: Self::Init) -> ServiceManager<Self> {
34        ServiceManager::new(init, 1, 1)
35    }
36
37    fn message(
38        &mut self,
39        _input: Self::Input,
40        _output_sender: &broadcast::Sender<Self::Output>,
41    ) -> impl std::future::Future<Output = ()> + Send {
42        async {}
43    }
44
45    fn event_generator(&mut self) -> impl std::future::Future<Output = Self::Event> + Send {
46        async {
47            azalea_log::error!(Self, "Event generator not implemented!");
48        }
49    }
50
51    fn event_handler(
52        &mut self,
53        _event: Self::Event,
54        _output_sender: &broadcast::Sender<Self::Output>,
55    ) -> impl std::future::Future<Output = anyhow::Result<()>> + Send {
56        async { Ok(()) }
57    }
58}
59
60pub use anyhow::Result;