dsf_core/api/
mod.rs

1//! API module defines the DSF remote API
2//! This allows for limited capability devices to perform network operations via
3//! a full-featured device
4
5use crate::types::Id;
6
7/// ServiceHandle objects are used to pass around instances of a service
8#[derive(Debug, Clone, PartialEq)]
9pub struct ServiceHandle {
10    pub id: Id,
11}
12
13impl ServiceHandle {
14    pub fn new(id: Id) -> Self {
15        Self { id }
16    }
17}
18
19/// Creation API used to create services
20pub trait Create {
21    type Options;
22    type Error;
23
24    /// Create a new service with the provided options
25    fn create(&mut self, options: Self::Options) -> Result<ServiceHandle, Self::Error>;
26}
27
28/// Producer API trait used to register an existing service
29pub trait Register {
30    type Options;
31    type Info;
32    type Error;
33
34    /// Register a service in the distributed database
35    fn register(&mut self, options: Self::Options) -> Result<Self::Info, Self::Error>;
36}
37
38/// Locate API trait used to find an existing service
39pub trait Locate {
40    type Options;
41    type Info;
42    type Error;
43
44    /// Locate a DIoT service in the distributed database
45    /// This returns a future that will resolve to the desired service or an error
46    fn locate(&mut self, options: Self::Options) -> Result<Self::Info, Self::Error>;
47}
48
49/// Publisher API trait used by publishers of service data
50pub trait Publish {
51    type Options;
52    type Info;
53    type Error;
54
55    /// Publish service data
56    fn publish(&mut self, options: Self::Options) -> Result<Self::Info, Self::Error>;
57}
58
59/// A boxed future stream to shorten method definitions
60/// //pub type FutureStream<E> = impl Stream<Item=E>;
61
62/// Subscriber API used by subscribers to service data
63pub trait Subscribe {
64    type Options;
65    type Streamable;
66    type Error;
67
68    /// Locate a DIoT service in the distributed database
69    /// This returns a future that will resolve to the desired service or an error
70    fn subscribe(&mut self, options: Self::Options) -> Result<Self::Streamable, Self::Error>;
71}