use smol_str::SmolStr;
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(default)
)]
#[cfg_attr(
feature = "quickcheck",
derive(::quickcheck_richderive::Arbitrary),
quickcheck(arbitrary = "crate::quickcheck_helpers::composite::capture_device")
)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Device {
make: SmolStr,
model: SmolStr,
}
impl Default for Device {
#[cfg_attr(not(tarpaulin), inline(always))]
fn default() -> Self {
Self::new()
}
}
impl Device {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new() -> Self {
Self {
make: SmolStr::new_static(""),
model: SmolStr::new_static(""),
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn make(&self) -> &str {
self.make.as_str()
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn model(&self) -> &str {
self.model.as_str()
}
#[must_use]
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_make(mut self, make: impl Into<SmolStr>) -> Self {
self.make = make.into();
self
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_make(&mut self, make: impl Into<SmolStr>) -> &mut Self {
self.make = make.into();
self
}
#[must_use]
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_model(mut self, model: impl Into<SmolStr>) -> Self {
self.model = model.into();
self
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_model(&mut self, model: impl Into<SmolStr>) -> &mut Self {
self.model = model.into();
self
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn is_empty(&self) -> bool {
self.make.is_empty() && self.model.is_empty()
}
}
#[cfg(test)]
mod tests;