mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 17:26:31 +00:00
@ -873,3 +873,45 @@ impl DeviceMatcher<&str> for DeviceMatchName {
|
||||
return device.name() == data;
|
||||
}
|
||||
}
|
||||
|
||||
/// Cookie to identify the device
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DeviceId {
|
||||
data: Option<&'static str>,
|
||||
allocated: Option<String>,
|
||||
}
|
||||
|
||||
impl DeviceId {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(data: Option<&'static str>, allocated: Option<String>) -> Option<Self> {
|
||||
if data.is_none() && allocated.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// 如果data和allocated都有值,那么返回None
|
||||
if data.is_some() && allocated.is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(Self { data, allocated });
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
if self.data.is_some() {
|
||||
return Some(self.data.unwrap());
|
||||
} else {
|
||||
return self.allocated.as_deref();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_allocated(&mut self, allocated: String) {
|
||||
self.allocated = Some(allocated);
|
||||
self.data = None;
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for DeviceId {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
return self.id() == other.id();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user