miden_objects/account/component/template/storage/
init_storage_data.rs

1use alloc::collections::BTreeMap;
2
3use super::{StoragePlaceholder, StorageValue};
4
5/// Represents the data required to initialize storage entries when instantiating an
6/// [AccountComponent](crate::account::AccountComponent) from a
7/// [template](crate::account::AccountComponentTemplate).
8#[derive(Clone, Debug, Default)]
9pub struct InitStorageData {
10    /// A mapping of storage placeholder names to their corresponding storage values.
11    storage_placeholders: BTreeMap<StoragePlaceholder, StorageValue>,
12}
13
14impl InitStorageData {
15    /// Creates a new instance of [InitStorageData].
16    ///
17    /// # Parameters
18    ///
19    /// - `entries`: An iterable collection of key-value pairs.
20    pub fn new(entries: impl IntoIterator<Item = (StoragePlaceholder, StorageValue)>) -> Self {
21        InitStorageData {
22            storage_placeholders: entries.into_iter().collect(),
23        }
24    }
25
26    /// Retrieves a reference to the storage placeholders.
27    pub fn placeholders(&self) -> &BTreeMap<StoragePlaceholder, StorageValue> {
28        &self.storage_placeholders
29    }
30
31    /// Returns a reference to the [StorageValue] corresponding to the placeholder, or
32    /// [`Option::None`] if the placeholder is not present.
33    pub fn get(&self, key: &StoragePlaceholder) -> Option<&StorageValue> {
34        self.storage_placeholders.get(key)
35    }
36}