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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use alloc::collections::BTreeMap;

use super::{StoragePlaceholder, StorageValue};

/// Represents the data required to initialize storage entries when instantiating an
/// [AccountComponent](crate::account::AccountComponent) from a
/// [template](crate::account::AccountComponentTemplate).
#[derive(Clone, Debug, Default)]
pub struct InitStorageData {
    /// A mapping of storage placeholder names to their corresponding storage values.
    storage_placeholders: BTreeMap<StoragePlaceholder, StorageValue>,
}

impl InitStorageData {
    /// Creates a new instance of [InitStorageData].
    ///
    /// # Parameters
    ///
    /// - `entries`: An iterable collection of key-value pairs.
    pub fn new(entries: impl IntoIterator<Item = (StoragePlaceholder, StorageValue)>) -> Self {
        InitStorageData {
            storage_placeholders: entries.into_iter().collect(),
        }
    }

    /// Retrieves a reference to the storage placeholders.
    pub fn placeholders(&self) -> &BTreeMap<StoragePlaceholder, StorageValue> {
        &self.storage_placeholders
    }

    /// Returns a reference to the [StorageValue] corresponding to the placeholder, or
    /// [`Option::None`] if the placeholder is not present.
    pub fn get(&self, key: &StoragePlaceholder) -> Option<&StorageValue> {
        self.storage_placeholders.get(key)
    }
}