Commit 1a1da281d1
Unsigned
Layout: unified · split
src/config.rs +2 −4
| @@ -27,6 +27,7 @@ use std::ops::{Deref, DerefMut}; | ||
| 27 | 27 | use std::rc::Rc; |
| 28 | 28 | |
| 29 | 29 | config!( |
| 30 | "matrix-rust", | |
| 30 | 31 | Section look { |
| 31 | 32 | encrypted_room_sign: String { |
| 32 | 33 | // Description. |
| @@ -47,10 +48,7 @@ pub struct ConfigHandle { | ||
| 47 | 48 | impl ConfigHandle { |
| 48 | 49 | /// Create a new config and wrap it in our config handle. |
| 49 | 50 | pub fn new(servers: &Servers) -> ConfigHandle { |
| 50 | let config = Weechat::config_new("matrix-rust") | |
| 51 | .expect("Can't create new config"); | |
| 52 | ||
| 53 | let config = Config::new(config); | |
| 51 | let config = Config::new().expect("Can't create new config"); | |
| 54 | 52 | |
| 55 | 53 | let config = ConfigHandle { |
| 56 | 54 | inner: Rc::new(RefCell::new(config)), |
src/config_macros.rs +7 −3
| @@ -237,6 +237,8 @@ macro_rules! section { | ||
| 237 | 237 | /// } |
| 238 | 238 | /// |
| 239 | 239 | /// config!( |
| 240 | /// // The name of the config | |
| 241 | /// "my-plugin", | |
| 240 | 242 | /// Section look { |
| 241 | 243 | /// encrypted_room_sign: String { |
| 242 | 244 | /// // Description. |
| @@ -305,7 +307,7 @@ macro_rules! section { | ||
| 305 | 307 | /// ); |
| 306 | 308 | /// ``` |
| 307 | 309 | macro_rules! config { |
| 308 | ($(Section $section:ident { $($option:tt)* }), * $(,)?) => { | |
| 310 | ($config_name:literal, $(Section $section:ident { $($option:tt)* }), * $(,)?) => { | |
| 309 | 311 | #[allow(unused_imports)] |
| 310 | 312 | use strum::VariantNames; |
| 311 | 313 | pub struct Config(weechat::config::Config); |
| @@ -325,11 +327,13 @@ macro_rules! config { | ||
| 325 | 327 | } |
| 326 | 328 | |
| 327 | 329 | impl Config { |
| 328 | fn new(config: weechat::config::Config) -> Self { | |
| 330 | fn new() -> Result<Self, ()> { | |
| 331 | let config = Weechat::config_new($config_name)?; | |
| 329 | 332 | let mut config = Config(config); |
| 333 | ||
| 330 | 334 | config.create_sections(); |
| 331 | 335 | |
| 332 | config | |
| 336 | Ok(config) | |
| 333 | 337 | } |
| 334 | 338 | |
| 335 | 339 | paste::item! { |