Crate loirc [] [src]

This library's goal is to offer a highly available IRC client with an easy to use API. Automatic reconnection is built into the design. It uses a channel-like design, where events are received from a Reader and commands are sent from one or many Writer.

The Writer are thread safe and can be cheaply cloned.

Here's a canonical example.

extern crate encoding;
extern crate loirc;

use encoding::all::UTF_8;
use loirc::{connect, Code, Event};

fn main() {
    // connect to freenode and use the default reconnection settings.
    let (writer, reader) = connect("irc.freenode.net:6667", Default::default(), UTF_8).unwrap();
    writer.raw(format!("USER {} 8 * :{}\n", "username", "realname"));
    writer.raw(format!("NICK {}\n", "nickname"));
    // Block until something happens.
    for event in reader.iter() {
        match event {
            // Handle messages
            Event::Message(msg) => {
                if msg.code == Code::RplWelcome {
                    writer.raw(format!("JOIN {}\n", "#channel"));
                }
            }
            // Handle other events, such as disconnects.
            _ => {}
        }
    }
}

Structs

ActivityMonitor

This struct monitors a connection's activity.

Message

Represents a message received from the server.

MonitorSettings

These settings tell the monitor how to behave.

PrefixUser

User prefix representation.

Writer

Used to send messages to the IRC server.

Enums

Code

Representation of IRC commands, replies and errors.

Error

Errors produced by the Writer.

Event

This is the comprehensive set of events that can occur.

ParseError

Error generated by the parser.

Prefix

Prefix of the message.

ReconnectionSettings

These settings tell the reconnection process how to behave.

Functions

connect

Create a connection to the given address.

Type Definitions

Reader

This the receiving end of a mpsc channel.