[][src]Struct ellidri_tokens::Buffer

pub struct Buffer { /* fields omitted */ }

Helper to build IRC messages.

The Buffer is used to ease the creation of strings representing valid IRC messages. If you mainly need to send replies, ReplyBuffer might be a better fit for you.

Example

let mut response = Buffer::new();

response.message("nick!user@127.0.0.1", Command::Topic)
    .param("#hall")
    .trailing_param("Welcome to new users!");
response.message("ellidri.dev", rpl::TOPIC)
    .param("nickname")
    .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 Buffer::message calls. These functions reseve MESSAGE_LENGTH prior to writing on the internal buffer.

Methods

impl Buffer[src]

pub fn new() -> Self[src]

Creates a Buffer. Does not allocate.

pub fn with_capacity(capacity: usize) -> Self[src]

pub fn is_empty(&self) -> bool[src]

Whether the buffer is empty.

Example

let empty = Buffer::new();
let mut not_empty = Buffer::new();

not_empty.message("ellidri.dev", Command::Motd);

assert_eq!(empty.is_empty(), true);
assert_eq!(not_empty.is_empty(), false);

pub fn get(&self) -> &str[src]

Returns a reference to the underlying String.

pub fn clear(&mut self)[src]

Empties the buffer.

pub fn len(&self) -> usize[src]

pub fn capacity(&self) -> usize[src]

pub fn reserve(&mut self, capacity: usize)[src]

pub fn message<C>(&mut self, prefix: &str, command: C) -> MessageBuffer where
    C: Into<Command>, 
[src]

Appends an IRC message with a prefix to the buffer.

This function may allocate to reserve space for the message.

Example

let mut response = Buffer::new();

response.message("unneeded_prefix", Command::Admin);

assert_eq!(&response.build(), ":unneeded_prefix ADMIN\r\n");

pub fn tagged_message(&mut self, client_tags: &str) -> TagBuffer[src]

Start building an IRC message with tags.

Server tags are filtered from client_tags, so that only tags with the client prefix + are appended to the buffer.

The length of the resulting tags (@ and included) is written to tags_len.

TODO example

pub fn build(self) -> String[src]

Consumes the Buffer and returns the underlying String.

Trait Implementations

impl Debug for Buffer[src]

impl Default for Buffer[src]

impl From<String> for Buffer[src]

Auto Trait Implementations

impl RefUnwindSafe for Buffer

impl Send for Buffer

impl Sync for Buffer

impl Unpin for Buffer

impl UnwindSafe for Buffer

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.