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