Skip to main content

config/
reloadable.rs

1use crate::{Configuration, OwnedSection, Section};
2use std::rc::Rc;
3use std::sync::Arc;
4use tokens::{ChangeToken, NeverChangeToken};
5
6/// Defines the behavior of a reloadable configuration.
7pub trait Reloadable: Sized {
8    /// Gets a value indicating whether the configuration can be reloaded.
9    fn can_reload(&self) -> bool;
10
11    /// Gets a [change token](ChangeToken) that will be notified when the configuration is reloaded.
12    fn reload_token(&self) -> impl ChangeToken + 'static;
13}
14
15macro_rules! unreloadable {
16    ($type:ty) => {
17        impl Reloadable for $type {
18            #[inline]
19            fn can_reload(&self) -> bool {
20                false
21            }
22
23            #[inline]
24            fn reload_token(&self) -> impl ChangeToken + 'static {
25                NeverChangeToken
26            }
27        }
28    };
29}
30
31unreloadable!(Configuration);
32unreloadable!(Section<'_>);
33unreloadable!(OwnedSection);
34
35macro_rules! reloadable {
36    ($type:ty) => {
37        impl Reloadable for $type {
38            #[inline]
39            fn can_reload(&self) -> bool {
40                (&**self).can_reload()
41            }
42
43            #[inline]
44            fn reload_token(&self) -> impl ChangeToken + 'static {
45                (&**self).reload_token()
46            }
47        }
48    };
49}
50
51reloadable!(Arc<Configuration>);
52reloadable!(Rc<Configuration>);