dimas_com/traits/
methods.rs

1// Copyright © 2024 Stephan Kunz
2
3//! Traits for communication capabilities.
4//!
5
6// region:      --- modules
7use crate::error::Error;
8use dimas_core::{
9	error::Result,
10	message_types::{Message, QueryableMsg},
11};
12// endregion:   --- modules
13
14// region:		--- CommunicatorMethods
15/// the communication methods to be implemented by a single session Communicator implementation
16#[allow(clippy::module_name_repetitions)]
17pub trait CommunicatorMethods {
18	/// Send a put message [`Message`] to the given `selector`.
19	/// # Errors
20	/// - `NotImplemented`: there is no implementation within this communicator
21	fn put(&self, _selector: &str, _message: Message) -> Result<()> {
22		Err(Error::NotImplemented.into())
23	}
24
25	/// Send a delete message to the given `selector`.
26	/// # Errors
27	/// - `NotImplemented`: there is no implementation within this communicator
28	fn delete(&self, _selector: &str) -> Result<()> {
29		Err(Error::NotImplemented.into())
30	}
31
32	/// Send a query with an optional specification [`Message`] to the given `selector`.
33	/// # Errors
34	/// - `NotImplemented`: there is no implementation within this communicator
35	fn get(
36		&self,
37		_selector: &str,
38		_message: Option<Message>,
39		_callback: Option<&mut dyn FnMut(QueryableMsg) -> Result<()>>,
40	) -> Result<()> {
41		Err(Error::NotImplemented.into())
42	}
43
44	/// Request an observation for [`Message`] from the given `selector`
45	/// # Errors
46	/// - `NotImplemented`: there is no implementation within this communicator
47	fn observe(&self, _selector: &str, _message: Option<Message>) -> Result<()> {
48		Err(Error::NotImplemented.into())
49	}
50
51	/// Request a stream configured by [`Message`] from the given `selector`
52	/// # Errors
53	/// - `NotImplemented`: there is no implementation within this communicator
54	fn watch(&self, _selector: &str, _message: Message) -> Result<()> {
55		Err(Error::NotImplemented.into())
56	}
57
58	/* not used currently
59	/// Send a put message [`Message`] from the given `session` to the given `selector`.
60	/// # Errors
61	/// - `NotImplemented`: there is no implementation within this communicator
62	fn put_from(&self, _session_id: &str, _selector: &str, _message: Message) -> Result<()> {
63		Err(Error::NotImplemented.into())
64	}
65
66	/// Send a delete message from the given `session` to the given `selector`.
67	/// # Errors
68	/// - `NotImplemented`: there is no implementation within this communicator
69	fn delete_from(&self, _session_id: &str, _selector: &str) -> Result<()> {
70		Err(Error::NotImplemented.into())
71	}
72
73	/// Send a query with an optional specification [`Message`] from the given `session` to the given `selector`.
74	/// # Errors
75	/// - `NotImplemented`: there is no implementation within this communicator
76	fn get_from(
77		&self,
78		_session_id: &str,
79		_selector: &str,
80		_message: Option<Message>,
81		_callback: Option<&mut dyn FnMut(QueryableMsg) -> Result<()>>,
82	) -> Result<()> {
83		Err(Error::NotImplemented.into())
84	}
85
86	/// Request an observation for [`Message`] from the given `session` from the given `selector`
87	/// # Errors
88	/// - `NotImplemented`: there is no implementation within this communicator
89	fn observe_from(
90		&self,
91		_session: &str,
92		_selector: &str,
93		_message: Option<Message>,
94	) -> Result<()> {
95		Err(Error::NotImplemented.into())
96	}
97
98	/// Request a stream configured by [`Message`] from the given `session` from the given `selector`
99	/// # Errors
100	/// - `NotImplemented`: there is no implementation within this communicator
101	fn watch_from(&self, _session: &str, _selector: &str, _message: Message) -> Result<()> {
102		Err(Error::NotImplemented.into())
103	}
104	*/
105}
106// endregion:	--- CommunicatorMethods
107
108// region:		--- CommunicatorImplementation
109/// the communication methods to be implemented by any Communicator implementation
110#[allow(clippy::module_name_repetitions)]
111pub trait CommunicatorImplementationMethods {
112	/// Send a put message [`Message`] to the given `selector`.
113	/// # Errors
114	/// - `NotImplemented`: there is no implementation within this communicator
115	fn put(&self, _selector: &str, _message: Message) -> Result<()> {
116		Err(Error::NotImplemented.into())
117	}
118
119	/// Send a delete message to the given `selector`.
120	/// # Errors
121	/// - `NotImplemented`: there is no implementation within this communicator
122	fn delete(&self, _selector: &str) -> Result<()> {
123		Err(Error::NotImplemented.into())
124	}
125
126	/// Send a query with an optional specification [`Message`] to the given `selector`.
127	/// # Errors
128	/// - `NotImplemented`: there is no implementation within this communicator
129	fn get(
130		&self,
131		_selector: &str,
132		_message: Option<Message>,
133		_callback: Option<&mut dyn FnMut(QueryableMsg) -> Result<()>>,
134	) -> Result<()> {
135		Err(Error::NotImplemented.into())
136	}
137
138	/// Request an observation for [`Message`] from the given `selector`
139	/// # Errors
140	/// - `NotImplemented`: there is no implementation within this communicator
141	fn observe(&self, _selector: &str, _message: Option<Message>) -> Result<()> {
142		Err(Error::NotImplemented.into())
143	}
144
145	/// Request a stream configured by [`Message`] from the given `selector`
146	/// # Errors
147	/// - `NotImplemented`: there is no implementation within this communicator
148	fn watch(&self, _selector: &str, _message: Message) -> Result<()> {
149		Err(Error::NotImplemented.into())
150	}
151}
152// endregion:	---CommunicatorImplementation