ntex_amqp/
default.rs

1use std::marker::PhantomData;
2
3use ntex::service::{Service, ServiceCtx, ServiceFactory};
4
5use crate::error::LinkError;
6use crate::{types::Link, ControlFrame, State};
7
8/// Default publish service
9pub(crate) struct DefaultPublishService<S, E>(PhantomData<(S, E)>);
10
11impl<S, E> Default for DefaultPublishService<S, E> {
12    fn default() -> Self {
13        DefaultPublishService(PhantomData)
14    }
15}
16
17impl<S, E> ServiceFactory<Link<S>, State<S>> for DefaultPublishService<S, E> {
18    type Response = ();
19    type Error = E;
20    type InitError = LinkError;
21    type Service = DefaultPublishService<S, E>;
22
23    async fn create(&self, _: State<S>) -> Result<Self::Service, Self::InitError> {
24        Err(LinkError::force_detach().description("not configured"))
25    }
26}
27
28impl<S, E> Service<Link<S>> for DefaultPublishService<S, E> {
29    type Response = ();
30    type Error = E;
31
32    async fn call(
33        &self,
34        _: Link<S>,
35        _: ServiceCtx<'_, Self>,
36    ) -> Result<Self::Response, Self::Error> {
37        log::warn!("AMQP Publish service is not configured");
38        Ok(())
39    }
40}
41
42/// Default control service
43pub struct DefaultControlService<S, E>(PhantomData<(S, E)>);
44
45impl<S, E> Default for DefaultControlService<S, E> {
46    fn default() -> Self {
47        DefaultControlService(PhantomData)
48    }
49}
50
51impl<S, E> ServiceFactory<ControlFrame, State<S>> for DefaultControlService<S, E> {
52    type Response = ();
53    type Error = E;
54    type InitError = E;
55    type Service = DefaultControlService<S, E>;
56
57    async fn create(&self, _: State<S>) -> Result<Self::Service, Self::InitError> {
58        Ok(DefaultControlService(PhantomData))
59    }
60}
61
62impl<S, E> Service<ControlFrame> for DefaultControlService<S, E> {
63    type Response = ();
64    type Error = E;
65
66    async fn call(
67        &self,
68        _: ControlFrame,
69        _: ServiceCtx<'_, Self>,
70    ) -> Result<Self::Response, Self::Error> {
71        Ok(())
72    }
73}