Skip to content

Commit

Permalink
Use NSStringEncoding::name in Debug impl
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Sep 20, 2020
1 parent b74db5e commit feda6cf
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions src/foundation/ns_string/encoding.rs
Expand Up @@ -11,35 +11,12 @@ pub struct NSStringEncoding(pub NSUInteger);

impl fmt::Debug for NSStringEncoding {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Format like an enum.
let name: &str = match *self {
Self::ASCII => &"ASCII",
Self::NEXTSTEP => &"NEXTSTEP",
Self::JapaneseEUC => &"JapaneseEUC",
Self::UTF8 => &"UTF8",
Self::ISOLatin1 => &"ISOLatin1",
Self::Symbol => &"Symbol",
Self::NonLossyASCII => &"NonLossyASCII",
Self::ShiftJIS => &"ShiftJIS",
Self::ISOLatin2 => &"ISOLatin2",
Self::WindowsCP1251 => &"WindowsCP1251",
Self::WindowsCP1252 => &"WindowsCP1252",
Self::WindowsCP1253 => &"WindowsCP1253",
Self::WindowsCP1254 => &"WindowsCP1254",
Self::WindowsCP1250 => &"WindowsCP1250",
Self::ISO2022JP => &"ISO2022JP",
Self::MacOSRoman => &"MacOSRoman",
Self::UTF16 => &"UTF16", // Same as `Unicode`
Self::UTF16BigEndian => &"UTF16BigEndian",
Self::UTF16LittleEndian => &"UTF16LittleEndian",
Self::UTF32 => &"UTF32",
Self::UTF32BigEndian => &"UTF32BigEndian",
Self::UTF32LittleEndian => &"UTF32LittleEndian",
_ => {
return f.debug_tuple("Other").field(&self.0).finish();
}
};
fmt::Display::fmt(name, f)
// SAFETY: The unretained string does not live long.
if let Some(name) = unsafe { self.name_unretained() } {
name.fmt(f)
} else {
f.debug_tuple("Unknown").field(&self.0).finish()
}
}
}

Expand Down

0 comments on commit feda6cf

Please sign in to comment.