Buttplug sex toy control library
at dev 2.8 kB view raw
1use getset::{Getters, MutGetters}; 2use serde::{Deserialize, Serialize}; 3 4/// Identifying information for devices that are currently connected or have connected in the past. 5/// 6/// Contains the 3 fields needed to uniquely identify a device in the system. Unlike 7/// [ConfigurationDeviceIdentifier]s, [UserDeviceIdentifier] will always have a device address 8/// available. 9/// 10/// NOTE: UserDeviceIdentifiers are NOT portable across platforms. For instance, bluetooth addresses 11/// are used for the address field on bluetooth devices. These will differ between all platforms due 12/// to address formatting as well as available information (macOS/iOS and WebBluetooth obfuscate 13/// bluetooth addresses) 14#[derive(Debug, Eq, PartialEq, Hash, Clone, Getters, MutGetters, Serialize, Deserialize)] 15#[getset(get = "pub", get_mut = "pub(crate)")] 16pub struct UserDeviceIdentifier { 17 /// Name of the protocol used 18 protocol: String, 19 /// Internal identifier for the protocol used 20 identifier: Option<String>, 21 /// Address, as possibly serialized by whatever the managing library for the Device Communication Manager is. 22 address: String, 23} 24 25impl UserDeviceIdentifier { 26 /// Creates a new instance 27 pub fn new(address: &str, protocol: &str, identifier: &Option<String>) -> Self { 28 Self { 29 address: address.to_owned(), 30 protocol: protocol.to_owned(), 31 identifier: identifier.clone(), 32 } 33 } 34} 35 36/// Set of information used for matching devices to their features and related communication protocol. 37#[derive(Debug, Clone, PartialEq, Eq, Hash, Getters, MutGetters, Serialize, Deserialize)] 38#[getset(get = "pub(crate)", get_mut = "pub(crate)")] 39pub struct BaseDeviceIdentifier { 40 /// Name of the protocol this device uses to communicate 41 protocol: String, 42 /// Some([identifier]) if there's an identifier, otherwise None if default 43 identifier: Option<String>, 44} 45 46impl BaseDeviceIdentifier { 47 pub fn new_default(protocol: &str) -> Self { 48 Self::new(protocol, &None) 49 } 50 51 pub fn new_with_identifier(protocol: &str, attributes_identifier: &str) -> Self { 52 Self::new(protocol, &Some(attributes_identifier.to_owned())) 53 } 54 55 pub fn new(protocol: &str, attributes_identifier: &Option<String>) -> Self { 56 Self { 57 protocol: protocol.to_owned(), 58 identifier: attributes_identifier.clone(), 59 } 60 } 61} 62 63impl From<&UserDeviceIdentifier> for BaseDeviceIdentifier { 64 fn from(other: &UserDeviceIdentifier) -> Self { 65 Self { 66 protocol: other.protocol().clone(), 67 identifier: other.identifier().clone(), 68 } 69 } 70} 71 72impl PartialEq<UserDeviceIdentifier> for BaseDeviceIdentifier { 73 fn eq(&self, other: &UserDeviceIdentifier) -> bool { 74 self.protocol == *other.protocol() && self.identifier == *other.identifier() 75 } 76}