#![cfg_attr(
test,
allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::indexing_slicing,
clippy::as_conversions
)
)]
pub mod analysis;
pub mod beat;
pub mod dbserver;
pub mod device;
pub mod djl;
pub mod rpc;
pub mod status;
mod error;
mod status_templates;
pub use device::{BrowsableDeviceNumber, DeviceKind, DeviceName, DeviceNumber, MacAddress};
pub use error::{Error, Result};
pub(crate) fn to_bytes<T>(value: &T) -> Vec<u8>
where
T: binrw::BinWrite + for<'a> binrw::meta::WriteEndian,
for<'a> <T as binrw::BinWrite>::Args<'a>: Default,
{
let mut out = std::io::Cursor::new(Vec::new());
#[expect(
clippy::expect_used,
reason = "writing to a Vec cannot fail; see the doc comment"
)]
binrw::BinWrite::write(value, &mut out).expect("encoding into a Vec cannot fail");
out.into_inner()
}
pub const MAGIC: [u8; 10] = *b"Qspt1WmJOL";
pub const DISCOVERY_PORT: u16 = 50000;
pub const BEAT_PORT: u16 = 50001;
pub const STATUS_PORT: u16 = 50002;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Slot(pub u8);
impl Slot {
pub const NONE: Self = Self(0);
pub const CD: Self = Self(1);
pub const SD: Self = Self(2);
pub const USB: Self = Self(3);
pub const REKORDBOX: Self = Self(4);
pub fn name(self) -> &'static str {
match self {
Self::NONE => "none",
Self::CD => "cd",
Self::SD => "sd",
Self::USB => "usb",
Self::REKORDBOX => "rekordbox",
_ => "unknown",
}
}
pub fn parse(name: &str) -> Option<Self> {
Some(match name.to_ascii_lowercase().as_str() {
"none" => Self::NONE,
"cd" => Self::CD,
"sd" => Self::SD,
"usb" => Self::USB,
"rb" | "rekordbox" => Self::REKORDBOX,
_ => return None,
})
}
}
impl core::fmt::Debug for Slot {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
Self::NONE | Self::CD | Self::SD | Self::USB | Self::REKORDBOX => {
f.write_str(self.name())
}
Self(raw) => write!(f, "Slot({raw:#04x})"),
}
}
}
impl core::fmt::Display for Slot {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(self, f)
}
}