diff --git a/src/netmd/base.rs b/src/netmd/base.rs index 1b7a643..b873dd3 100644 --- a/src/netmd/base.rs +++ b/src/netmd/base.rs @@ -15,6 +15,7 @@ const BULK_WRITE_ENDPOINT: u8 = 0x02; const BULK_READ_ENDPOINT: u8 = 0x81; nofmt::pls! { // Skip formatting the following info +/// Device IDs for use in matching existing devices pub static DEVICE_IDS: &[DeviceId] = &[ DeviceId { vendor_id: 0x04dd, product_id: 0x7202, name: Some("Sharp IM-MT899H") }, DeviceId { vendor_id: 0x04dd, product_id: 0x9013, name: Some("Sharp IM-DR400") }, @@ -65,6 +66,7 @@ pub static DEVICE_IDS: &[DeviceId] = &[ ]; } +/// Device IDs for use with [cross_usb] pub static DEVICE_IDS_CROSSUSB: Lazy> = Lazy::new(|| { DEVICE_IDS .iter() @@ -136,7 +138,7 @@ impl NetMD { if device_type.vendor_id == model.vendor_id && device_type.product_id == model.product_id { - model.name = device_type.name.clone(); + model.name = device_type.name; break; } } diff --git a/src/netmd/commands.rs b/src/netmd/commands.rs index f402524..0082115 100644 --- a/src/netmd/commands.rs +++ b/src/netmd/commands.rs @@ -398,11 +398,7 @@ impl NetMDContext { new_fw_name: Option<&str>, ) -> Result<(), Box> { let new_name = sanitize_half_width_title(new_name); - let new_fw_name = if let Some(name) = new_fw_name { - Some(sanitize_full_width_title(name)) - } else { - None - }; + let new_fw_name = new_fw_name.map(sanitize_full_width_title); let old_name = self.interface.disc_title(false).await?; let old_fw_name = self.interface.disc_title(true).await?; diff --git a/src/netmd/interface.rs b/src/netmd/interface.rs index 14b8eb9..06975ac 100644 --- a/src/netmd/interface.rs +++ b/src/netmd/interface.rs @@ -76,12 +76,12 @@ pub enum Encoding { LP4 = 0x93, } -impl ToString for Encoding { - fn to_string(&self) -> String { +impl std::fmt::Display for Encoding { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Encoding::SP => String::from("sp"), - Encoding::LP2 => String::from("lp2"), - Encoding::LP4 => String::from("lp4"), + Encoding::SP => write!(f, "sp"), + Encoding::LP2 => write!(f, "lp2"), + Encoding::LP4 => write!(f, "lp4"), } } } @@ -92,11 +92,11 @@ pub enum Channels { Stereo = 0x00, } -impl ToString for Channels { - fn to_string(&self) -> String { +impl std::fmt::Display for Channels { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Channels::Mono => String::from("mono"), - Channels::Stereo => String::from("stereo"), + Channels::Mono => write!(f, "mono"), + Channels::Stereo => write!(f, "stereo"), } } } @@ -112,11 +112,11 @@ pub enum TrackFlag { Unprotected = 0x00, } -impl ToString for TrackFlag { - fn to_string(&self) -> String { +impl std::fmt::Display for TrackFlag { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - TrackFlag::Protected => String::from("protected"), - TrackFlag::Unprotected => String::from("unprotected"), + TrackFlag::Protected => write!(f, "protected"), + TrackFlag::Unprotected => write!(f, "unprotected"), } } } diff --git a/src/netmd/mappings.rs b/src/netmd/mappings.rs index 435b866..a83585b 100644 --- a/src/netmd/mappings.rs +++ b/src/netmd/mappings.rs @@ -1,6 +1,7 @@ use phf::phf_map; -pub static MAPPINGS_JP: phf::Map<&'static str, &'static str> = phf_map![ +/// Mappings to convert to fullwidth from half width +pub static MAPPINGS_JP: phf::Map<&str, &str> = phf_map![ "!" =>"!", "\"" =>""", "#" =>"#", @@ -191,7 +192,9 @@ pub static MAPPINGS_JP: phf::Map<&'static str, &'static str> = phf_map![ "。" =>"。", "、" =>"、" ]; -pub static MAPPINGS_RU: phf::Map<&'static str, &'static str> = phf_map![ + +/// Mappings to romanize Russian +pub static MAPPINGS_RU: phf::Map<&str, &str> = phf_map![ "а" =>"a", "б" =>"b", "в" =>"v", @@ -259,7 +262,9 @@ pub static MAPPINGS_RU: phf::Map<&'static str, &'static str> = phf_map![ "Ю" =>"Iu", "Я" =>"Ia" ]; -pub static MAPPINGS_DE: phf::Map<&'static str, &'static str> = phf_map![ + +/// Mappings to remove accents for German +pub static MAPPINGS_DE: phf::Map<&str, &str> = phf_map![ "Ä" => "Ae", "ä" => "ae", "Ö" => "Oe", @@ -268,7 +273,9 @@ pub static MAPPINGS_DE: phf::Map<&'static str, &'static str> = phf_map![ "ü" => "ue", "ß" => "ss" ]; -pub static MAPPINGS_HW: phf::Map<&'static str, &'static str> = phf_map![ + +/// Mappings to make Japanese half width +pub static MAPPINGS_HW: phf::Map<&str, &str> = phf_map![ "-" =>"-", "ー" =>"-", "ァ" =>"ァ", @@ -548,7 +555,9 @@ pub static MAPPINGS_HW: phf::Map<&'static str, &'static str> = phf_map![ "ゝ" =>"ヽ", "ゞ" =>"ヾ", ]; -pub static ALLOWED_HW_KANA: &[&'static str] = &[ + +/// A list of allowed half width kana +pub static ALLOWED_HW_KANA: &[&str] = &[ "-", "-", "ァ", "ア", "ィ", "イ", "ゥ", "ウ", "ェ", "エ", "ォ", "オ", "カ", "ガ", "キ", "ギ", "ク", "グ", "ケ", "ゲ", "コ", "ゴ", "サ", "ザ", "シ", "ジ", "ス", "ズ", "セ", "ゼ", "ソ", "ゾ", "タ", "ダ", "チ", "ヂ", "ッ", "ツ", "ヅ", "テ", "デ", "ト", "ド", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "バ", "パ", "ヒ", @@ -566,6 +575,8 @@ pub static ALLOWED_HW_KANA: &[&'static str] = &[ "マ", "ミ", "ム", "メ", "モ", "ャ", "ヤ", "ュ", "ユ", "ョ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ワ", "ヲ", "ン", "ヮ", "ヰ", "ヱ", "ヵ", "ヶ", "ヴ", "ヽ", "ヾ", ]; + +/// Characters which take up more than one byte pub static MULTI_BYTE_CHARS: phf::Map = phf_map![ 'ガ' => 1, 'ギ' => 1, @@ -634,6 +645,8 @@ pub static MULTI_BYTE_CHARS: phf::Map = phf_map![ 'ゝ' => 1, 'ゞ' => 1 ]; + +/// Half width to full width conversion for group ranges pub static HW_TO_FW_RANGE_MAP: phf::Map = phf_map![ '0' => '0', '1' => '1',