Fix up docs

This commit is contained in:
Yash Karandikar 2021-11-04 12:02:40 -05:00
parent 2201c6970f
commit 87154e3385
Signed by: karx
GPG key ID: A794DA2529474BA5
3 changed files with 24 additions and 10 deletions

View file

@ -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"

View file

@ -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<Self, Error> {
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<Command, ()> {
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<br>
/// username: Username to join the IRC with<br>
/// ```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<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let mut file = File::open(&path)?;

View file

@ -1,4 +1,4 @@
use irsc::{Client, Command, Config};
use circe::{Client, Command, Config};
#[allow(unused_macros)]
macro_rules! loop_n {