eirc 0.0.0

Event-based/Extensible Internet Relay Chat library.
Documentation
use super::string::IrcString;

#[derive(Clone, PartialEq, Eq)]
pub enum IrcCommand {
  Textual(IrcString),
  Numeric(u16) // 0-999, 999 > 255 (u8), 999 < 65535 (u16)
}

#[derive(Clone, PartialEq, Eq)]
pub struct IrcLine {
  command: IrcCommand,
  arguments: Vec<IrcString>,
  //ext: LineExt,
}

#[derive(Clone, PartialEq, Eq)]
pub struct IrcLineBuilder {
  command: Option<IrcCommand>,
  arguments: Vec<IrcString>,
  //ext: LineExt,
}

impl IrcLineBuilder {
  pub fn new() -> IrcLineBuilder {
    IrcLineBuilder {
      command: None,
      arguments: Vec::new(),
      //ext: LineExt::new(),
    }
  }

  pub fn get_command(&self) -> &Option<IrcCommand> {
    &self.command
  }

  pub fn set_command(&mut self, command: Option<IrcCommand>) {
    self.command = command;
  }

  pub fn build(self) -> Result<IrcLine, Self> {
    //! Attempts to build the IrcLine.
    //!
    //! Returns `Ok(IrcLine)` if the line was successfuly built. `Err(self)` otherwise.
    match self {
      IrcLineBuilder {
        command: Some(command),
        arguments,
        //ext,
      } => {
        Ok(IrcLine {
          command: command,
          arguments: arguments,
          //ext: ext,
        })
      }
      _ => Err(self)
    }
  }
}