aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 79c2581fd9cdc2a3936fc495da591c7bfac0a90d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#![feature(plugin, custom_derive, slice_patterns)]
#![plugin(regex_macros)]
#![cfg_attr(feature = "lints", plugin(clippy))]

#![deny(warnings)]
#![allow(unused_imports)]

extern crate regex;
#[macro_use]
extern crate log;
extern crate openssl;
extern crate encoding;
extern crate linear_map;

pub mod client;
pub mod color;
pub mod ident;
pub mod callback;
pub mod message;
pub mod command;
pub mod reply;
pub mod event;
pub mod text;

use std::io;
use std::result;
use std::ops::{ Deref, DerefMut };

use openssl::ssl::error::SslError;

use encoding::EncodingRef;

pub use ident::Ident;
pub use message::Message;
pub use command::Command;
pub use reply::Reply;
pub use event::Event;
pub use client::Client;

#[derive(Debug)]
pub enum IrscError {
    Io(io::Error),
    AlreadyConnected,
    NotConnected,
    NotFound,
    Ssl(SslError)
}

impl From<SslError> for IrscError {
    fn from(e: SslError) -> IrscError { IrscError::Ssl(e) }
}

pub struct Result<T>(result::Result<T, IrscError>);

impl<T> Deref for Result<T> {
    type Target = result::Result<T, IrscError>;
    fn deref(&self) -> &result::Result<T, IrscError> { &self.0 }
}

impl<T> DerefMut for Result<T> {
    fn deref_mut(&mut self) -> &mut result::Result<T, IrscError> { &mut self.0 }
}

impl<T> Result<T> { fn inner(self) -> result::Result<T, IrscError> { self.0 } }

pub const DEBUG: bool = cfg!(debug_assertions);
pub static ENCODING: EncodingRef = encoding::all::UTF_8;