diff --git a/src/gopher/type.rs b/src/gopher/type.rs index 1d05d6c..8413442 100644 --- a/src/gopher/type.rs +++ b/src/gopher/type.rs @@ -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, "{}", '?') + } + } +}