Skip to main content

motorcortex_rust/connection/
connection_trait.rs

1use crate::{ConnectionOptions, Request, Subscribe};
2
3/// Define a common trait for connection management
4pub trait Connection {
5    /// Connect to a server
6    fn connect(&mut self, url: &str, options: ConnectionOptions) -> Result<(), String>;
7
8    /// Disconnect from the server
9    fn disconnect(&mut self) -> Result<(), String>;
10}
11
12/// Implement the common trait for `Request`
13impl Connection for Request {
14    fn connect(&mut self, url: &str, options: ConnectionOptions) -> Result<(), String> {
15        self.connect(url, options)
16    }
17
18    fn disconnect(&mut self) -> Result<(), String> {
19        self.disconnect()
20    }
21}
22
23/// Implement the common trait for `Subscribe`
24impl Connection for Subscribe {
25    fn connect(&mut self, url: &str, options: ConnectionOptions) -> Result<(), String> {
26        self.connect(url, options)
27    }
28
29    fn disconnect(&mut self) -> Result<(), String> {
30        self.disconnect()
31    }
32}