common_data_model/
custom_traits.rs

1use serde::{Deserialize, Serialize};
2
3/// A trait for custom serialization and deserialization.
4///
5/// Provides methods to convert the implementing type to and from JSON strings.
6pub trait CustomSerializer<T> {
7    /// Serializes the implementor into a JSON string.
8    ///
9    /// # Errors
10    /// Returns an error if serialization fails.
11    fn to_json_string(&self) -> String
12    where
13        Self: Serialize,
14        Self: Sized,
15    {
16        serde_json::to_string(&self).expect("Error during serialization")
17    }
18    /// Deserializes an instance of the implementing type from a JSON string.
19    ///
20    /// # Arguments
21    ///
22    /// * `data_string` - A string slice containing the JSON representation.
23    ///
24    /// # Errors
25    /// Returns an error if deserialization fails.
26
27    fn from_json_string(data_string: String) -> T
28    where
29        T: for<'a> Deserialize<'a>,
30    {
31        serde_json::from_str(&data_string).expect("Error during deserialization")
32    }
33}
34
35pub trait IMacVendorCache {
36    fn new() -> Self;
37    fn add(&self, mac_addr: String, vendor_name: String);
38    fn contains(&self, mac_addr: &String) -> bool;
39    fn get(&self, mac_addr: &String) -> String;
40    fn length(&self) -> usize;
41}