Commit 1a1da281d1

1a1da281d1ca2cbded84d37079d7407c3926ce83

parent: 3c75741c89

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-06-27 16:54 UTC

config: Allow setting the config name in the macro.

Layout: unified · split

src/config.rs +2 −4
@@ -27,6 +27,7 @@ use std::ops::{Deref, DerefMut};
2727use std::rc::Rc;
2828
2929config!(
30 "matrix-rust",
3031 Section look {
3132 encrypted_room_sign: String {
3233 // Description.
@@ -47,10 +48,7 @@ pub struct ConfigHandle {
4748impl ConfigHandle {
4849 /// Create a new config and wrap it in our config handle.
4950 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");
5452
5553 let config = ConfigHandle {
5654 inner: Rc::new(RefCell::new(config)),
src/config_macros.rs +7 −3
@@ -237,6 +237,8 @@ macro_rules! section {
237237/// }
238238///
239239/// config!(
240/// // The name of the config
241/// "my-plugin",
240242/// Section look {
241243/// encrypted_room_sign: String {
242244/// // Description.
@@ -305,7 +307,7 @@ macro_rules! section {
305307/// );
306308/// ```
307309macro_rules! config {
308 ($(Section $section:ident { $($option:tt)* }), * $(,)?) => {
310 ($config_name:literal, $(Section $section:ident { $($option:tt)* }), * $(,)?) => {
309311 #[allow(unused_imports)]
310312 use strum::VariantNames;
311313 pub struct Config(weechat::config::Config);
@@ -325,11 +327,13 @@ macro_rules! config {
325327 }
326328
327329 impl Config {
328 fn new(config: weechat::config::Config) -> Self {
330 fn new() -> Result<Self, ()> {
331 let config = Weechat::config_new($config_name)?;
329332 let mut config = Config(config);
333
330334 config.create_sections();
331335
332 config
336 Ok(config)
333337 }
334338
335339 paste::item! {