INNER CODE UNIT · Rust

set_storage

gosub-io/gosub-engine · crates/gosub_config/src/lib.rs:89

    pub fn set_storage(&self, storage: Box<dyn StorageAdapter>) {
        self.0.write().set_storage(storage);
    }

    /// Merges every setting from `other` into this config under an optional namespace.
    ///
    /// Each of `other`'s settings is registered here as `"{namespace}.{key}"` (or bare `key` when
    /// `namespace` is empty), carrying over its description, default, constraint and current value.
    /// One-time snapshot, not a live link: later changes in `other` are not reflected here. Keys
    /// that already exist are left untouched (and logged). Merged settings are not written to this
    /// config's storage adapter unless later `set`. Returns the number of settings merged.
    pub fn merge(&self, other: &Config, namespace: &str) -> usize {
        // Snapshot `other` first (its read guard is released at the end of this statement) so that
        // acquiring our own write lock can never overlap with it - safe even if `other` is a clone
        // of `self`.
        let entries = other.0.read().snapshot();
        self.0.write().absorb(entries, namespace)
    }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…