ic_memory/slot/
descriptor.rs1use crate::validation::Validate;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
12#[serde(deny_unknown_fields)]
13pub enum AllocationSlot {
14 MemoryManagerId(u8),
16}
17
18#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
25#[serde(deny_unknown_fields)]
26pub struct AllocationSlotDescriptor {
27 pub(crate) slot: AllocationSlot,
29 pub(crate) substrate: String,
31 pub(crate) descriptor_version: u32,
33}
34
35impl AllocationSlotDescriptor {
36 #[must_use]
38 pub const fn slot(&self) -> &AllocationSlot {
39 &self.slot
40 }
41
42 #[must_use]
44 pub fn substrate(&self) -> &str {
45 &self.substrate
46 }
47
48 #[must_use]
50 pub const fn descriptor_version(&self) -> u32 {
51 self.descriptor_version
52 }
53}
54
55impl Validate for AllocationSlotDescriptor {
56 type Error = AllocationSlotDescriptorError;
57
58 fn validate(&self) -> Result<(), Self::Error> {
59 self.memory_manager_id()
60 .map(|_| ())
61 .map_err(AllocationSlotDescriptorError::MemoryManager)
62 }
63}
64
65#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
70pub enum AllocationSlotDescriptorError {
71 #[error(transparent)]
73 MemoryManager(super::memory_manager::MemoryManagerSlotError),
74}