1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2018 atter developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.

//! Configuration management for atter.
//!
//! # Examples
//!
//! ## Read from TOML string
//!
//! ```
//! # #[macro_use] extern crate error_chain;
//! # extern crate atter;
//! # extern crate toml;
//! #
//! # use atter::{read_toml, Config};
//! # use std::io::Cursor;
//! #
//! # mod error {
//! #     error_chain!{
//! #         foreign_links {
//! #             Io(::std::io::Error);
//! #             atter(::atter::Error);
//! #             TomlDe(::toml::de::Error);
//! #             TomlSer(::toml::ser::Error);
//! #         }
//! #     }
//! # }
//! #
//! # fn main() {
//! #     read().expect("")
//! # }
//! #
//! # fn read() -> error::Result<()> {
//!     let test_toml = r#"base_url = "http://docs.rs/atter"
//!     "#;
//!
//!     // Serialize the TOML above into a `Config` struct.
//!     let mut reader = Cursor::new(test_toml);
//!     let config = read_toml(&mut reader)?;
//!
//!     // Check the `Config` struct.
//!     let base_url = config.base_url();
//!     assert_eq!(base_url, "http://docs.rs/atter");
//!
//! #   Ok(())
//! # }
//! ```
//!
//! ## Write to TOML string
//!
//! ```
//! # #[macro_use] extern crate error_chain;
//! # extern crate atter;
//! # extern crate toml;
//! #
//! # use atter::{write_toml, Config};
//! # use std::io::Cursor;
//! #
//! # mod error {
//! #     error_chain!{
//! #         foreign_links {
//! #             Io(::std::io::Error);
//! #             atter(::atter::Error);
//! #             TomlDe(::toml::de::Error);
//! #             TomlSer(::toml::ser::Error);
//! #         }
//! #     }
//! # }
//! #
//! # const TEST_TOML: &str = r#"base_url = "http://docs.rs/atter"
//! # "#;
//! #
//! # fn main() {
//! #     write().expect("unable to write");
//! # }
//! #
//! # fn write() -> error::Result<()> {
//!       // Setup the `Config` struct.
//!       let mut config: Config = Default::default();
//!       config.set_base_url("http://docs.rs/atter".to_string());
//!
//!       // Write the TOML to the given buf.
//!       let mut buf = [0; 5000];
//!
//!       // Wrapped to drop mutable borrow.
//!       {
//!         let mut writer = Cursor::new(&mut buf[..]);
//!         write_toml(&config, &mut writer)?;
//!       }
//!
//!       // Check that the result is the same as the TOML above.
//!       let filtered = buf.iter().filter(|x| **x > 0).cloned().collect::<Vec<u8>>();
//!       assert_eq!(
//!           TEST_TOML,
//!           String::from_utf8(filtered).expect("Invalid UTF-8 in result")
//!       );
//! #   Ok(())
//! # }
//! ```
//!
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate getset;
#[macro_use]
extern crate serde_derive;

#[cfg(test)]
extern crate bincode;
extern crate regex;
extern crate toml;
extern crate url;
extern crate uuid;

mod config;
mod error;
mod message;

pub use config::{read_toml, write_toml, Config};
pub use error::Error;
pub use message::Message;