to_char always works

pull/22/head
chris west 4 years ago
parent 23c76e483b
commit 7fb209206a

@ -93,8 +93,8 @@ impl Type {
} }
/// Gopher Item Type to RFC char. /// Gopher Item Type to RFC char.
pub fn to_char(self) -> Option<char> { pub fn to_char(self) -> char {
Some(match self { match self {
Type::Text => '0', Type::Text => '0',
Type::Menu => '1', Type::Menu => '1',
Type::CSOEntity => '2', Type::CSOEntity => '2',
@ -118,7 +118,7 @@ impl Type {
Type::Calendar => 'c', Type::Calendar => 'c',
Type::Xml => 'x', Type::Xml => 'x',
Type::Mailbox => 'M', Type::Mailbox => 'M',
}) }
} }
/// Create a Gopher Item Type from its RFC char code. /// Create a Gopher Item Type from its RFC char code.
@ -154,10 +154,6 @@ impl Type {
impl fmt::Display for Type { impl fmt::Display for Type {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(c) = self.to_char() { write!(f, "{}", self.to_char())
write!(f, "{}", c)
} else {
write!(f, "?")
}
} }
} }

@ -46,7 +46,7 @@ pub fn append(filename: &str, label: &str, url: &str) -> Result<()> {
write!( write!(
file, file,
"{}{}\t{}\t{}\t{}\r\n", "{}{}\t{}\t{}\t{}\r\n",
u.typ.to_char().unwrap_or('i'), u.typ.to_char(),
label, label,
u.sel, u.sel,
u.host, u.host,
@ -76,7 +76,7 @@ pub fn prepend(filename: &str, label: &str, url: &str) -> Result<()> {
write!( write!(
file, file,
"{}{}\t{}\t{}\t{}\r\n", "{}{}\t{}\t{}\t{}\r\n",
url.typ.to_char().unwrap_or('i'), url.typ.to_char(),
label, label,
url.sel, url.sel,
url.host, url.host,

Loading…
Cancel
Save