diff --git a/src/proto/chan.rs b/src/proto/chan.rs new file mode 100644 index 0000000..fb1dc4c --- /dev/null +++ b/src/proto/chan.rs @@ -0,0 +1,22 @@ +//! An extension trait that provides the ability to check if a string is a channel name. + +/// An extension trait giving strings a function to check if they are a channel. +pub trait ChannelExt { + /// Returns true if the specified name is a channel name. + fn is_channel_name(&self) -> bool; +} + +impl<'a> ChannelExt for &'a str { + fn is_channel_name(&self) -> bool { + self.starts_with("#") || + self.starts_with("&") || + self.starts_with("+") || + self.starts_with("!") + } +} + +impl ChannelExt for String { + fn is_channel_name(&self) -> bool { + (&self[..]).is_channel_name() + } +} diff --git a/src/proto/command.rs b/src/proto/command.rs index 26b087b..3737f3c 100644 --- a/src/proto/command.rs +++ b/src/proto/command.rs @@ -3,7 +3,7 @@ use std::ascii::AsciiExt; use std::str::FromStr; use error; -use proto::{ChannelMode, Mode, Response, UserMode}; +use proto::{ChannelExt, ChannelMode, Mode, Response, UserMode}; /// List of all client commands as defined in [RFC 2812](http://tools.ietf.org/html/rfc2812). This /// also includes commands from the @@ -1754,18 +1754,3 @@ impl FromStr for BatchSubCommand { } } } - -/// An extension trait giving strings a function to check if they are a channel. -pub trait ChannelExt { - /// Returns true if the specified name is a channel name. - fn is_channel_name(&self) -> bool; -} - -impl<'a> ChannelExt for &'a str { - fn is_channel_name(&self) -> bool { - self.starts_with("#") || - self.starts_with("&") || - self.starts_with("+") || - self.starts_with("!") - } -} diff --git a/src/proto/mod.rs b/src/proto/mod.rs index 7f7ec72..6d46691 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -1,6 +1,7 @@ //! Support for the IRC protocol using Tokio. pub mod caps; +pub mod chan; pub mod command; pub mod irc; pub mod line; @@ -9,6 +10,7 @@ pub mod mode; pub mod response; pub use self::caps::{Capability, NegotiationVersion}; +pub use self::chan::ChannelExt; pub use self::command::{BatchSubCommand, CapSubCommand, Command}; pub use self::irc::IrcCodec; pub use self::message::Message;