use getset::{Getters, MutGetters};
use serde::{Deserialize, Serialize};
#[derive(Debug, Eq, PartialEq, Hash, Clone, Getters, MutGetters, Serialize, Deserialize)]
#[getset(get = "pub", get_mut = "pub(crate)")]
pub struct UserDeviceIdentifier {
protocol: String,
identifier: Option<String>,
address: String,
}
impl UserDeviceIdentifier {
pub fn new(address: &str, protocol: &str, identifier: &Option<String>) -> Self {
Self {
address: address.to_owned(),
protocol: protocol.to_owned(),
identifier: identifier.clone(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Getters, MutGetters, Serialize, Deserialize)]
#[getset(get = "pub", get_mut = "pub(crate)")]
pub struct BaseDeviceIdentifier {
protocol: String,
identifier: Option<String>,
}
impl BaseDeviceIdentifier {
pub fn new_default(protocol: &str) -> Self {
Self::new(protocol, &None)
}
pub fn new_with_identifier(protocol: &str, attributes_identifier: &str) -> Self {
Self::new(protocol, &Some(attributes_identifier.to_owned()))
}
pub fn new(protocol: &str, attributes_identifier: &Option<String>) -> Self {
Self {
protocol: protocol.to_owned(),
identifier: attributes_identifier.clone(),
}
}
}
impl From<&UserDeviceIdentifier> for BaseDeviceIdentifier {
fn from(other: &UserDeviceIdentifier) -> Self {
Self {
protocol: other.protocol().clone(),
identifier: other.identifier().clone(),
}
}
}
impl PartialEq<UserDeviceIdentifier> for BaseDeviceIdentifier {
fn eq(&self, other: &UserDeviceIdentifier) -> bool {
self.protocol == *other.protocol() && self.identifier == *other.identifier()
}
}