type gets impl fmt::Display

pull/14/head
chris west 4 years ago
parent 3c321c53da
commit 692fbbc554

@ -1,3 +1,5 @@
use std::fmt;
/// Gopher types are defined according to RFC 1436.
#[allow(missing_docs)]
#[derive(Copy, Clone, PartialEq, Debug)]
@ -29,6 +31,16 @@ impl Type {
self == Type::Info
}
/// HTML link?
pub fn is_html(self) -> bool {
self == Type::HTML
}
/// Telnet link?
pub fn is_telnet(self) -> bool {
self == Type::Telnet
}
/// Is this a link, ie something we can navigate to or open?
pub fn is_link(self) -> bool {
match self {
@ -113,3 +125,13 @@ impl Type {
})
}
}
impl fmt::Display for Type {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(c) = self.to_char() {
write!(f, "{}", c)
} else {
write!(f, "{}", '?')
}
}
}

Loading…
Cancel
Save