Refactored ChannelExt into its own module.

This commit is contained in:
Aaron Weiss 2017-06-25 04:46:20 -04:00
parent a7a20efb0c
commit 30468870bf
No known key found for this signature in database
GPG key ID: 0237035D9BF03AE2
3 changed files with 25 additions and 16 deletions

22
src/proto/chan.rs Normal file
View file

@ -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()
}
}

View file

@ -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("!")
}
}

View file

@ -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;