fundamentum_iot_mqtt_proto/lib.rs
1//! Rust bindings to Fundamentum IoT MQTT *gRPC* IDL files.
2//! A library that provides a Rust representation of the basic types, interfaces and
3//! other components required to define and interact with the *gRPC* interface defined
4//! by [`fundamentum-iot-mqtt-proto`][repo-proto].
5//!
6//! Current direct users:
7//!
8//! - [`fundamentum-edge-daemon`][repo-daemon]: the actual edge daemon server
9//! implementation.
10//!
11//! [repo-proto]: https://bitbucket.org/amotus/fundamentum-iot-mqtt-proto
12//! [repo-daemon]: https://bitbucket.org/amotus/fundamentum-edge-daemon
13
14mod error;
15
16pub use error::Error;
17
18use std::{fmt::Display, str::FromStr};
19
20/// The rust bindings generated from the protobuf files under `./proto/`.
21///
22/// Mirrors original protobuf top level 'com' namespace.
23pub mod com {
24 /// Mirrors original protobuf namespace at 'com.fundamentum'.
25 ///
26 /// Exposes Fundamentum related protobuf symbols.
27 pub mod fundamentum {
28 /// Mirrors original protobuf namespace at 'com.fundamentum.actions'.
29 ///
30 /// Exposes Fundamentum's actions related protobuf symbols.
31 pub mod actions {
32 pub use v1 as latest;
33 /// Mirrors original protobuf namespace at 'com.fundamentum.actions.v1'.
34 ///
35 /// Exposes Fundamentum's actions related protobuf symbols as of version 1
36 pub mod v1 {
37 use crate::Version;
38
39 include!(concat!(env!("OUT_DIR"), "/com.fundamentum.actions.v1.rs"));
40
41 /// Get current version
42 pub fn get_version() -> Version {
43 Version::V1
44 }
45 }
46 }
47 }
48}
49
50/// Protocol version
51#[derive(Debug, Clone)]
52pub enum Version {
53 V1,
54}
55
56impl FromStr for Version {
57 type Err = Error;
58
59 fn from_str(input: &str) -> Result<Version, Self::Err> {
60 match input {
61 "1" => Ok(Version::V1),
62 _ => Err(Error::InvalidVersion),
63 }
64 }
65}
66
67impl Display for Version {
68 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
69 match self {
70 Version::V1 => write!(f, "1"),
71 }
72 }
73}