use crate::validation::Validate;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(deny_unknown_fields)]
pub enum AllocationSlot {
MemoryManagerId(u8),
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(deny_unknown_fields)]
pub struct AllocationSlotDescriptor {
pub(crate) slot: AllocationSlot,
pub(crate) substrate: String,
pub(crate) descriptor_version: u32,
}
impl AllocationSlotDescriptor {
#[must_use]
pub const fn slot(&self) -> &AllocationSlot {
&self.slot
}
#[must_use]
pub fn substrate(&self) -> &str {
&self.substrate
}
#[must_use]
pub const fn descriptor_version(&self) -> u32 {
self.descriptor_version
}
}
impl Validate for AllocationSlotDescriptor {
type Error = AllocationSlotDescriptorError;
fn validate(&self) -> Result<(), Self::Error> {
self.memory_manager_id()
.map(|_| ())
.map_err(AllocationSlotDescriptorError::MemoryManager)
}
}
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum AllocationSlotDescriptorError {
#[error(transparent)]
MemoryManager(super::memory_manager::MemoryManagerSlotError),
}