[][src]Struct ellidri_tokens::MessageBuffer

pub struct MessageBuffer<'a> { /* fields omitted */ }

Helper to build an IRC message.

Use with Buffer::message and ReplyBuffer::message.

Methods

impl<'a> MessageBuffer<'a>[src]

pub fn param(self, param: &str) -> Self[src]

Appends a parameter to the message.

The parameter is trimmed before insertion. If param is whitespace, it is not appended.

Note: It is up to the caller to make sure there is no remaning whitespace or newline in the parameter.

Example

let mut response = Buffer::new();

response.message("nick!user@127.0.0.1", Command::Quit)
    .param("")
    .param("  chiao ");

assert_eq!(&response.build(), ":nick!user@127.0.0.1 QUIT chiao\r\n");

pub fn fmt_param<T>(self, param: T) -> Self where
    T: Display
[src]

Formats, then appends a parameter to the message.

The parameter is NOT trimmed before insertion, is appended even if it's empty. Use Buffer::param to append strings, especially untrusted ones.

Note: It is up to the caller to make sure there is no remaning whitespace or newline in the parameter.

Example

let mut response = Buffer::new();

response.message("", Command::PrivMsg)
    .fmt_param("  #space ")
    .fmt_param(42);

assert_eq!(&response.build(), "PRIVMSG   #space  42\r\n");

pub fn trailing_param(self, param: &str)[src]

Appends the traililng parameter to the message and consumes the buffer.

Contrary to MessageBuffer::param, the parameter is not trimmed before insertion. Even if param is just whitespace, it is appended.

Note: It is up to the caller to make sure there is no newline in the parameter.

Example

let mut response = Buffer::new();

response.message("nick!user@127.0.0.1", Command::Quit)
    .trailing_param("long quit message");

assert_eq!(&response.build(), ":nick!user@127.0.0.1 QUIT :long quit message\r\n");

pub fn raw_param(&mut self) -> &mut String[src]

Returns a buffer the caller can use to append characters to an IRC message.

Example

let mut response = Buffer::new();
{
    let mut msg = response.message("nick!user@127.0.0.1", Command::Mode)
        .param("#my_channel");
    let mut param = msg.raw_param();
    param.push('+');
    param.push('n');
    param.push('t');
}

assert_eq!(&response.build(), ":nick!user@127.0.0.1 MODE #my_channel +nt\r\n");

pub fn raw_trailing_param(&mut self) -> &mut String[src]

Returns a buffer the caller can use to append characters to an IRC message.

Example

let mut response = Buffer::new();
{
    let mut msg = response.message("ellidri.dev", rpl::NAMREPLY)
        .param("ser");
    let mut param = msg.raw_trailing_param();
    param.push_str("@RandomChanOp");
    param.push(' ');
    param.push_str("RandomUser");
}

assert_eq!(&response.build(), ":ellidri.dev 353 ser :@RandomChanOp RandomUser\r\n");

Trait Implementations

impl<'_> Drop for MessageBuffer<'_>[src]

fn drop(&mut self)[src]

Auto-magically append "\r\n" when the MessageBuffer is dropped.

Auto Trait Implementations

impl<'a> RefUnwindSafe for MessageBuffer<'a>

impl<'a> Send for MessageBuffer<'a>

impl<'a> Sync for MessageBuffer<'a>

impl<'a> Unpin for MessageBuffer<'a>

impl<'a> !UnwindSafe for MessageBuffer<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.