Fix up docs
This commit is contained in:
parent
2201c6970f
commit
87154e3385
|
@ -1,6 +1,6 @@
|
||||||
channels = ["#main", "#main2"]
|
channels = ["#main", "#main2"]
|
||||||
host = "192.168.178.100"
|
host = "192.168.1.28"
|
||||||
mode = "+B"
|
mode = "+B"
|
||||||
nickname = "IRSC"
|
nickname = "circe"
|
||||||
port = 6667
|
port = 6667
|
||||||
username = "IRSC"
|
username = "circe"
|
||||||
|
|
26
src/lib.rs
26
src/lib.rs
|
@ -1,10 +1,11 @@
|
||||||
//! A simple IRC crate written in rust
|
//! A simple IRC crate written in rust
|
||||||
//! ```rust
|
//! ```rust
|
||||||
|
//! use circe::*;
|
||||||
//! fn main() -> Result<(), std::io::Error> {
|
//! fn main() -> Result<(), std::io::Error> {
|
||||||
//! let config = Config::from_toml("config.toml")?;
|
//! let config = Config::from_toml("config.toml")?;
|
||||||
//! let mut client = Client::new(config)?;
|
//! let mut client = Client::new(config)?;
|
||||||
//! client.identify()?;
|
//! client.identify()?;
|
||||||
//!
|
//!
|
||||||
//! loop {
|
//! loop {
|
||||||
//! if let Ok(ref command) = client.read() {
|
//! if let Ok(ref command) = client.read() {
|
||||||
//! if let Command::OTHER(line) = command {
|
//! if let Command::OTHER(line) = command {
|
||||||
|
@ -54,6 +55,7 @@ pub enum Command {
|
||||||
CAP(CapMode),
|
CAP(CapMode),
|
||||||
/// Joins a channel
|
/// Joins a channel
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// client.write_command(Command::JOIN("#main".to_string()))?;
|
/// client.write_command(Command::JOIN("#main".to_string()))?;
|
||||||
/// ```
|
/// ```
|
||||||
JOIN(
|
JOIN(
|
||||||
|
@ -62,6 +64,7 @@ pub enum Command {
|
||||||
),
|
),
|
||||||
/// Sets the mode of the user
|
/// Sets the mode of the user
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// client.write_command(Command::MODE("#main".to_string(), Some("+B")))?;
|
/// client.write_command(Command::MODE("#main".to_string(), Some("+B")))?;
|
||||||
/// ```
|
/// ```
|
||||||
/// If the MODE is not given (e.g. None), then the client will send "MODE target"
|
/// If the MODE is not given (e.g. None), then the client will send "MODE target"
|
||||||
|
@ -84,6 +87,7 @@ pub enum Command {
|
||||||
PONG(String),
|
PONG(String),
|
||||||
/// Sends a message in a channel
|
/// Sends a message in a channel
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// client.write_command(Command::PRIVMSG("#main".to_string(), "This is an example message".to_string()))?;
|
/// client.write_command(Command::PRIVMSG("#main".to_string(), "This is an example message".to_string()))?;
|
||||||
/// ```
|
/// ```
|
||||||
PRIVMSG(
|
PRIVMSG(
|
||||||
|
@ -112,9 +116,10 @@ impl Command {
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Creates a new client with a given config
|
/// Creates a new client with a given config
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// let mut client = Client::new(config)?;
|
/// let mut client = Client::new(config)?;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Errors if the client could not connect to the given host.
|
/// Errors if the client could not connect to the given host.
|
||||||
pub fn new(config: Config) -> Result<Self, Error> {
|
pub fn new(config: Config) -> Result<Self, Error> {
|
||||||
let stream = TcpStream::connect(format!("{}:{}", config.host, config.port))?;
|
let stream = TcpStream::connect(format!("{}:{}", config.host, config.port))?;
|
||||||
|
@ -123,9 +128,10 @@ impl Client {
|
||||||
|
|
||||||
/// Identify user and join the specified channels
|
/// Identify user and join the specified channels
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// client.identify()?;
|
/// client.identify()?;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Errors if the client could not write to the stream.
|
/// Errors if the client could not write to the stream.
|
||||||
pub fn identify(&mut self) -> Result<(), Error> {
|
pub fn identify(&mut self) -> Result<(), Error> {
|
||||||
self.write_command(Command::CAP(CapMode::END))?;
|
self.write_command(Command::CAP(CapMode::END))?;
|
||||||
|
@ -178,13 +184,18 @@ impl Client {
|
||||||
|
|
||||||
/// Read data coming from the IRC as a [`Command`]
|
/// Read data coming from the IRC as a [`Command`]
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
|
/// # fn main() -> Result<(), std::io::Error> {
|
||||||
|
/// # let config = Config::from_toml("config.toml");
|
||||||
|
/// # let client = Client::new(config)?;
|
||||||
/// if let Ok(ref command) = client.read() {
|
/// if let Ok(ref command) = client.read() {
|
||||||
/// if let Command::OTHER(line) = command {
|
/// if let Command::OTHER(line) = command {
|
||||||
/// print!("{}", line);
|
/// print!("{}", line);
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Errors if there are no new messages. This should not be taken as an actual Error, because nothing went wrong.
|
/// Errors if there are no new messages. This should not be taken as an actual Error, because nothing went wrong.
|
||||||
pub fn read(&mut self) -> Result<Command, ()> {
|
pub fn read(&mut self) -> Result<Command, ()> {
|
||||||
if let Some(string) = self.read_string() {
|
if let Some(string) = self.read_string() {
|
||||||
|
@ -207,9 +218,10 @@ impl Client {
|
||||||
|
|
||||||
/// Send a [`Command`] to the IRC
|
/// Send a [`Command`] to the IRC
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// client.write_command(Command::PRIVMSG("#main".to_string(), "Hello".to_string()))?;
|
/// client.write_command(Command::PRIVMSG("#main".to_string(), "Hello".to_string()))?;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Errors if the stream could not write.
|
/// Errors if the stream could not write.
|
||||||
pub fn write_command(&mut self, command: Command) -> Result<(), Error> {
|
pub fn write_command(&mut self, command: Command) -> Result<(), Error> {
|
||||||
use Command::*;
|
use Command::*;
|
||||||
|
@ -279,6 +291,7 @@ impl Config {
|
||||||
/// port: Port of the IRC server<br>
|
/// port: Port of the IRC server<br>
|
||||||
/// username: Username to join the IRC with<br>
|
/// username: Username to join the IRC with<br>
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// let config = Config::new(
|
/// let config = Config::new(
|
||||||
/// Box::new(["#main".to_string(), "#main2".to_string()]),
|
/// Box::new(["#main".to_string(), "#main2".to_string()]),
|
||||||
/// "192.168.178.100",
|
/// "192.168.178.100",
|
||||||
|
@ -308,6 +321,7 @@ impl Config {
|
||||||
|
|
||||||
/// Create a config from a toml file
|
/// Create a config from a toml file
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// # use circe::*;
|
||||||
/// let config = Config::from_toml("config.toml")?;
|
/// let config = Config::from_toml("config.toml")?;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -319,7 +333,7 @@ impl Config {
|
||||||
/// port = 6667
|
/// port = 6667
|
||||||
/// username = "IRSC"
|
/// username = "IRSC"
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Returns an Error if the file cannot be opened or if the TOML is invalid
|
/// Returns an Error if the file cannot be opened or if the TOML is invalid
|
||||||
pub fn from_toml<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
|
pub fn from_toml<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
|
||||||
let mut file = File::open(&path)?;
|
let mut file = File::open(&path)?;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use irsc::{Client, Command, Config};
|
use circe::{Client, Command, Config};
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! loop_n {
|
macro_rules! loop_n {
|
||||||
|
|
Loading…
Reference in a new issue