pub struct ConfigCell<T> { /* private fields */ }Expand description
Process-wide storage for one configuration type.
Lives in a static, which is the only place a device has to put anything
that outlives a function:
static SETTINGS: ConfigCell<Settings> = ConfigCell::new();§Why a critical section
A reader has to see either the old configuration or the new one, never a
mixture. On a host that is an ArcSwap; on a device without an allocator it
is a few instructions with interrupts masked, which is what
critical_section provides and what every embedded HAL implements.
The section is held for a clone of the value and nothing else. Keep the configuration struct small — which a device’s configuration is — and that is a memcpy with interrupts off, measured in microseconds.
Implementations§
Source§impl<T> ConfigCell<T>
impl<T> ConfigCell<T>
Source§impl<T: Clone> ConfigCell<T>
impl<T: Clone> ConfigCell<T>
Sourcepub fn store(&self, value: T)
pub fn store(&self, value: T)
Installs value, replacing whatever was there.
For compiled-in defaults at start-up, and for anything that builds a configuration without parsing one.
Source§impl<T: Clone + DeserializeOwned + Validate> ConfigCell<T>
impl<T: Clone + DeserializeOwned + Validate> ConfigCell<T>
Sourcepub fn apply(&self, document: &[u8], format: Format) -> Result<(), Error>
pub fn apply(&self, document: &[u8], format: Format) -> Result<(), Error>
Parses document and installs it, if it is usable.
Everything that can fail happens before anything is installed: a document that does not parse, does not fit, or does not validate leaves the previous configuration serving. That is the whole reason this is one call rather than parse-then-store.
§Errors
If the bytes are not valid in format, do not fit T, or T rejects
itself.