[−][src]Struct ellidri::message::ReplyBuffer
An helper to build IRC replies.
IRC replies are IRC messages that have the domain of the server as prefix, and the nickname of the client as first parameter.
Example
let mut response = ReplyBuffer::new("ellidri.dev", "nickname"); response.message("nick!user@127.0.0.1", Command::Topic) .param("#hall") .trailing_param("Welcome to new users!"); response.reply(rpl::TOPIC) .param("#hall") .trailing_param("Welcome to new users!"); let result = response.build(); assert_eq!(&result, ":nick!user@127.0.0.1 TOPIC #hall :Welcome to new users!\r\n\ :ellidri.dev 332 nickname #hall :Welcome to new users!\r\n");
On allocation
Allocation only occurs on ReplyBuffer::reply
and ReplyBuffer::message
calls. These
functions reseve MESSAGE_LENGTH
prior to writing on the internal buffer.
Usage note
This buffer uses thread-local storage to store the domain and the nickname, to reduce the
number of allocations. Therefore, the user must not make two ReplyBuffer
s at the same time,
otherwise nicknames and domains will be mixed.
Methods
impl ReplyBuffer
[src]
pub fn new(domain: &str, nickname: &str) -> Self
[src]
Creates a new ReplyBuffer
and initialize the thread-local storage with the given domain
and nickname.
pub fn is_empty(&self) -> bool
[src]
Whether the buffer has messages in it or not.
Example
let empty = ReplyBuffer::new("ellidri.dev", "ser"); let mut not_empty = ReplyBuffer::new("ellidri.dev", "ser"); not_empty.reply(rpl::ERR_NOMOTD); assert_eq!(empty.is_empty(), true); assert_eq!(not_empty.is_empty(), false);
pub fn reply<C>(&mut self, r: C) -> MessageBuffer where
C: Into<Command>,
[src]
C: Into<Command>,
Appends a reply to the buffer.
This will push the domain, the reply and the nickname of the client, and then return the
resulting MessageBuffer
.
This function may allocate to reserve space for the message.
Example
let mut response = ReplyBuffer::new("ellidri.dev", "ser"); response.reply(rpl::WELCOME).trailing_param("Welcome to IRC, ser"); assert_eq!(&response.build(), ":ellidri.dev 001 ser :Welcome to IRC, ser\r\n");
pub fn message<C>(&mut self, prefix: &str, command: C) -> MessageBuffer where
C: Into<Command>,
[src]
C: Into<Command>,
Appends a prefixed message like you would do with a Buffer
.
This function may allocate to reserve space for the message.
Example
let mut response = ReplyBuffer::new("ellidri.dev", "ser"); response.message("unneeded_prefix", Command::Admin); assert_eq!(&response.build(), ":unneeded_prefix ADMIN\r\n");
pub fn build(self) -> String
[src]
Consumes the buffer and returns the underlying String
.
Auto Trait Implementations
impl RefUnwindSafe for ReplyBuffer
impl Send for ReplyBuffer
impl Sync for ReplyBuffer
impl Unpin for ReplyBuffer
impl UnwindSafe for ReplyBuffer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,