create TYPES
This commit is contained in:
@@ -5,15 +5,17 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
pub mod helper;
|
pub mod helper;
|
||||||
pub mod influxdb_models;
|
pub mod influxdb_models;
|
||||||
mod mac;
|
|
||||||
pub mod unit_conversion;
|
pub mod unit_conversion;
|
||||||
|
|
||||||
pub type Antenna = antenna::Antenna;
|
mod types;
|
||||||
pub type Point = point::Point;
|
pub type Point = types::point::Point;
|
||||||
pub type MAC = mac::MAC;
|
pub type MAC = types::mac::MAC;
|
||||||
|
|
||||||
|
|
||||||
|
pub mod antenna;
|
||||||
|
pub type Antenna = antenna::Antenna;
|
||||||
|
|
||||||
|
|
||||||
mod antenna;
|
|
||||||
mod point;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct DeviceReport {
|
pub struct DeviceReport {
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
use std::fmt::{Debug, Display, Formatter};
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use influxdb::Type;
|
|
||||||
use serde::de::{self, Visitor};
|
|
||||||
use serde::{Deserialize, Serialize, Serializer};
|
|
||||||
|
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
#[derive(Default, Clone, Copy, Hash, PartialEq, Eq)]
|
#[derive(Default, Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
pub struct MAC {
|
pub struct MAC {
|
||||||
@@ -21,7 +14,11 @@ impl MAC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for MAC {
|
////////////////////////////////////////////////////
|
||||||
|
// Standard implementations:
|
||||||
|
//
|
||||||
|
|
||||||
|
impl std::str::FromStr for MAC {
|
||||||
type Err = std::string::ParseError;
|
type Err = std::string::ParseError;
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let mut m = MAC::default();
|
let mut m = MAC::default();
|
||||||
@@ -30,25 +27,33 @@ impl FromStr for MAC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for MAC {
|
impl std::fmt::Display for MAC {
|
||||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(f, "{}", String::from_utf8_lossy(&self.s))
|
write!(f, "{}", String::from_utf8_lossy(&self.s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for MAC {
|
impl std::fmt::Debug for MAC {
|
||||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(f, "{}", String::from_utf8_lossy(&self.s))
|
write!(f, "{}", String::from_utf8_lossy(&self.s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MAC> for Type {
|
////////////////////////////////////////////////////
|
||||||
|
// Influx implementations:
|
||||||
|
//
|
||||||
|
|
||||||
|
impl From<MAC> for influxdb::Type {
|
||||||
fn from(val: MAC) -> Self {
|
fn from(val: MAC) -> Self {
|
||||||
Type::Text(val.to_string())
|
influxdb::Type::Text(val.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for MAC {
|
////////////////////////////////////////////////////
|
||||||
|
// Serde implementations:
|
||||||
|
//
|
||||||
|
|
||||||
|
impl<'de> serde::Deserialize<'de> for MAC {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
@@ -57,7 +62,7 @@ impl<'de> Deserialize<'de> for MAC {
|
|||||||
len: usize,
|
len: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for MACVisitor {
|
impl<'de> serde::de::Visitor<'de> for MACVisitor {
|
||||||
type Value = MAC;
|
type Value = MAC;
|
||||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(formatter, "a string containing at least {} bytes", self.len)
|
write!(formatter, "a string containing at least {} bytes", self.len)
|
||||||
@@ -65,12 +70,15 @@ impl<'de> Deserialize<'de> for MAC {
|
|||||||
|
|
||||||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: serde::de::Error,
|
||||||
{
|
{
|
||||||
if s.len() == self.len {
|
if s.len() == self.len {
|
||||||
Ok(MAC::new(s))
|
Ok(MAC::new(s))
|
||||||
} else {
|
} else {
|
||||||
Err(de::Error::invalid_value(de::Unexpected::Str(s), &self))
|
Err(serde::de::Error::invalid_value(
|
||||||
|
serde::de::Unexpected::Str(s),
|
||||||
|
&self,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,10 +88,13 @@ impl<'de> Deserialize<'de> for MAC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for MAC {
|
impl serde::Serialize for MAC {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
|
fn serialize<S>(
|
||||||
|
&self,
|
||||||
|
serializer: S,
|
||||||
|
) -> Result<<S as serde::Serializer>::Ok, <S as serde::Serializer>::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: serde::Serializer,
|
||||||
{
|
{
|
||||||
serializer.serialize_str(self.as_str())
|
serializer.serialize_str(self.as_str())
|
||||||
}
|
}
|
||||||
2
kairo-common/src/types/mod.rs
Normal file
2
kairo-common/src/types/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod mac;
|
||||||
|
pub mod point;
|
||||||
Reference in New Issue
Block a user