rust-irc/irc-proto/src/chan.rs

23 lines
637 B
Rust
Raw Normal View History

//! 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 {
2019-08-27 15:05:51 +02:00
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()
}
}