From 87154e3385bb74421c99723892d496eb800d1a82 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Thu, 4 Nov 2021 12:02:40 -0500 Subject: [PATCH] Fix up docs --- config.toml | 6 +++--- src/lib.rs | 26 ++++++++++++++++++++------ src/main.rs | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/config.toml b/config.toml index e299357..d9fa710 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,6 @@ channels = ["#main", "#main2"] -host = "192.168.178.100" +host = "192.168.1.28" mode = "+B" -nickname = "IRSC" +nickname = "circe" port = 6667 -username = "IRSC" +username = "circe" diff --git a/src/lib.rs b/src/lib.rs index 9452ced..2ecd904 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,11 @@ //! A simple IRC crate written in rust //! ```rust +//! use circe::*; //! fn main() -> Result<(), std::io::Error> { //! let config = Config::from_toml("config.toml")?; //! let mut client = Client::new(config)?; //! client.identify()?; -//! +//! //! loop { //! if let Ok(ref command) = client.read() { //! if let Command::OTHER(line) = command { @@ -54,6 +55,7 @@ pub enum Command { CAP(CapMode), /// Joins a channel /// ```rust + /// # use circe::*; /// client.write_command(Command::JOIN("#main".to_string()))?; /// ``` JOIN( @@ -62,6 +64,7 @@ pub enum Command { ), /// Sets the mode of the user /// ```rust + /// # use circe::*; /// 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" @@ -84,6 +87,7 @@ pub enum Command { PONG(String), /// Sends a message in a channel /// ```rust + /// # use circe::*; /// client.write_command(Command::PRIVMSG("#main".to_string(), "This is an example message".to_string()))?; /// ``` PRIVMSG( @@ -112,9 +116,10 @@ impl Command { impl Client { /// Creates a new client with a given config /// ```rust + /// # use circe::*; /// let mut client = Client::new(config)?; /// ``` - /// + /// /// Errors if the client could not connect to the given host. pub fn new(config: Config) -> Result { let stream = TcpStream::connect(format!("{}:{}", config.host, config.port))?; @@ -123,9 +128,10 @@ impl Client { /// Identify user and join the specified channels /// ```rust + /// # use circe::*; /// client.identify()?; /// ``` - /// + /// /// Errors if the client could not write to the stream. pub fn identify(&mut self) -> Result<(), Error> { self.write_command(Command::CAP(CapMode::END))?; @@ -178,13 +184,18 @@ impl Client { /// Read data coming from the IRC as a [`Command`] /// ```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 Command::OTHER(line) = command { /// print!("{}", line); /// } /// } + /// # } /// ``` - /// + /// /// 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 { if let Some(string) = self.read_string() { @@ -207,9 +218,10 @@ impl Client { /// Send a [`Command`] to the IRC /// ```rust + /// # use circe::*; /// client.write_command(Command::PRIVMSG("#main".to_string(), "Hello".to_string()))?; /// ``` - /// + /// /// Errors if the stream could not write. pub fn write_command(&mut self, command: Command) -> Result<(), Error> { use Command::*; @@ -279,6 +291,7 @@ impl Config { /// port: Port of the IRC server
/// username: Username to join the IRC with
/// ```rust + /// # use circe::*; /// let config = Config::new( /// Box::new(["#main".to_string(), "#main2".to_string()]), /// "192.168.178.100", @@ -308,6 +321,7 @@ impl Config { /// Create a config from a toml file /// ```rust + /// # use circe::*; /// let config = Config::from_toml("config.toml")?; /// ``` /// @@ -319,7 +333,7 @@ impl Config { /// port = 6667 /// username = "IRSC" /// ``` - /// + /// /// Returns an Error if the file cannot be opened or if the TOML is invalid pub fn from_toml>(path: P) -> Result { let mut file = File::open(&path)?; diff --git a/src/main.rs b/src/main.rs index e987dc7..0f971c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use irsc::{Client, Command, Config}; +use circe::{Client, Command, Config}; #[allow(unused_macros)] macro_rules! loop_n {