Split toml into a crate feature
This commit is contained in:
parent
fa468f3bcd
commit
535718afba
19
Cargo.toml
19
Cargo.toml
|
@ -11,17 +11,24 @@ exclude = ["src/main.rs", "config.toml"]
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
toml = "0.5"
|
||||
serde_derive = "1.0"
|
||||
serde = "1.0"
|
||||
|
||||
[dependencies.native-tls]
|
||||
version= "0.2"
|
||||
optional = true
|
||||
|
||||
[dependencies.toml]
|
||||
version = "0.5"
|
||||
optional = true
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
|
||||
[dependencies.serde_derive]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
|
||||
[features]
|
||||
default = ["tls"]
|
||||
tls = ["native-tls"]
|
||||
debug = []
|
||||
|
||||
toml_support = ["toml", "serde", "serde_derive"]
|
||||
|
|
45
src/lib.rs
45
src/lib.rs
|
@ -2,7 +2,7 @@
|
|||
//! ```no_run
|
||||
//! use circe::{commands::Command, Client, Config};
|
||||
//! fn main() -> Result<(), std::io::Error> {
|
||||
//! let config = Config::from_toml("config.toml")?;
|
||||
//! let config = Default::default();
|
||||
//! let mut client = Client::new(config)?;
|
||||
//! client.identify()?;
|
||||
//!
|
||||
|
@ -73,7 +73,7 @@ impl Client {
|
|||
/// Creates a new client with a given [`Config`].
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let config = Config::from_toml("config.toml")?;
|
||||
/// # let config = Default::default();
|
||||
/// let mut client = Client::new(config)?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -105,7 +105,7 @@ impl Client {
|
|||
/// Identify user and joins the in the [`Config`] specified channels.
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.identify()?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -175,7 +175,7 @@ impl Client {
|
|||
/// # use circe::*;
|
||||
/// # use circe::commands::Command;
|
||||
/// # fn main() -> Result<(), std::io::Error> {
|
||||
/// # let config = Config::from_toml("config.toml")?;
|
||||
/// # let config = Default::default();
|
||||
/// # let mut client = Client::new(config)?;
|
||||
/// if let Ok(ref command) = client.read() {
|
||||
/// if let Command::OTHER(line) = command {
|
||||
|
@ -226,7 +226,7 @@ impl Client {
|
|||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # use circe::commands::Command;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.write_command(Command::PRIVMSG("".to_string(), "#main".to_string(), "Hello".to_string()))?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -354,7 +354,7 @@ impl Client {
|
|||
/// Helper function for requesting information about the ADMIN of an IRC server
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.admin("192.168.178.100")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -368,7 +368,7 @@ impl Client {
|
|||
/// Helper function for setting the users status to AWAY
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.away("AFK")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -382,7 +382,7 @@ impl Client {
|
|||
/// Helper function for sending PRIVMSGs.
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.privmsg("#main", "Hello")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -400,7 +400,7 @@ impl Client {
|
|||
/// Helper function to INVITE people to a channels
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.invite("liblirc", "#circe")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -417,7 +417,7 @@ impl Client {
|
|||
/// Helper function for sending JOINs.
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.join("#main")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -431,7 +431,7 @@ impl Client {
|
|||
/// Helper function for ``LISTing`` channels and modes
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.list(None, None)?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -447,7 +447,7 @@ impl Client {
|
|||
/// Helper function for getting all nicknames in a channel
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.names("#main,#circe", None)?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -468,7 +468,7 @@ impl Client {
|
|||
/// Helper function to try to register as a channel operator
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.oper("username", "password")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -485,7 +485,7 @@ impl Client {
|
|||
/// Helper function for sending MODEs.
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.mode("test", Some("+B"))?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -506,7 +506,7 @@ impl Client {
|
|||
/// Helper function for leaving channels.
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.part("#main")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -520,7 +520,7 @@ impl Client {
|
|||
/// Helper function for setting or getting the topic of a channel
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.topic("#main", Some("main channel"))?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -541,7 +541,7 @@ impl Client {
|
|||
/// Helper function for leaving the IRC server and shutting down the TCP stream afterwards.
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// # let mut client = Client::new(Config::from_toml("config.toml")?)?;
|
||||
/// # let mut client = Client::new(Default::default())?;
|
||||
/// client.quit(None)?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
|
@ -573,7 +573,7 @@ impl Config {
|
|||
/// ```rust
|
||||
/// # use circe::*;
|
||||
/// let config = Config::new(
|
||||
/// vec!["#main", "#circe"],
|
||||
/// &["#main", "#circe"],
|
||||
/// "192.168.178.100",
|
||||
/// Some("+B"),
|
||||
/// Some("circe"),
|
||||
|
@ -620,12 +620,9 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
/// _This feature requires the `toml_support` feature to be enabled._
|
||||
///
|
||||
/// Create a config from a toml file
|
||||
/// ```no_run
|
||||
/// # use circe::*;
|
||||
/// let config = Config::from_toml("config.toml")?;
|
||||
/// # Ok::<(), std::io::Error>(())
|
||||
/// ```
|
||||
/// ```toml
|
||||
/// channels = ["#main", "#main2"]
|
||||
/// host = "192.168.178.100"
|
||||
|
@ -636,6 +633,8 @@ impl Config {
|
|||
/// ```
|
||||
/// # Errors
|
||||
/// Returns an Error if the file cannot be opened or if the TOML is invalid
|
||||
///
|
||||
#[cfg(feature = "toml_support")]
|
||||
pub fn from_toml<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
|
||||
let mut file = File::open(&path)?;
|
||||
let mut data = String::new();
|
||||
|
|
|
@ -11,6 +11,7 @@ macro_rules! loop_n {
|
|||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
let config = Config::from_toml("config.toml")?;
|
||||
// let config = Default::default();
|
||||
let mut client = Client::new(config).unwrap();
|
||||
client.identify().unwrap();
|
||||
client.privmsg("#main", "Test")?;
|
||||
|
|
Loading…
Reference in a new issue