use core::{fmt::Debug, time::Duration};
use iceoryx2_bb_elementary::enum_gen;
use iceoryx2_bb_elementary_traits::testing::abandonable::Abandonable;
use iceoryx2_bb_memory::bump_allocator::BumpAllocator;
use iceoryx2_bb_posix::file::AccessMode;
use iceoryx2_bb_system_types::file_name::*;
use tiny_fn::tiny_fn;
use crate::static_storage::file::{NamedConcept, NamedConceptBuilder, NamedConceptMgmt};
tiny_fn! {
pub struct Initializer<T> = FnMut(value: &mut T, allocator: &mut BumpAllocator) -> bool;
}
impl<T> Debug for Initializer<'_, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "")
}
}
#[doc(hidden)]
pub mod dynamic_storage_configuration;
pub mod file;
pub mod posix_shared_memory;
pub mod process_local;
pub mod recommended;
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum DynamicStorageCreateError {
AlreadyExists,
InsufficientPermissions,
InitializationFailed,
InternalError,
}
impl core::fmt::Display for DynamicStorageCreateError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "DynamicStorageCreateError::{self:?}")
}
}
impl core::error::Error for DynamicStorageCreateError {}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum DynamicStorageOpenError {
DoesNotExist,
InitializationNotYetFinalized,
VersionMismatch,
InternalError,
}
impl core::fmt::Display for DynamicStorageOpenError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "DynamicStorageOpenError::{self:?}")
}
}
impl core::error::Error for DynamicStorageOpenError {}
enum_gen! {
DynamicStorageOpenOrCreateError
mapping:
DynamicStorageOpenError,
DynamicStorageCreateError
}
pub trait DynamicStorageBuilder<'builder, T: Send + Sync, D: DynamicStorage<T>>:
Debug + Sized + NamedConceptBuilder<D>
{
fn call_drop_on_destruction(self, value: bool) -> Self;
fn has_ownership(self, value: bool) -> Self;
fn supplementary_size(self, value: usize) -> Self;
fn timeout(self, value: Duration) -> Self;
fn initializer<F: FnMut(&mut T, &mut BumpAllocator) -> bool + 'builder>(self, value: F)
-> Self;
fn create(self, initial_value: T) -> Result<D, DynamicStorageCreateError>;
fn open(self, access_mode: AccessMode) -> Result<D, DynamicStorageOpenError>;
fn open_or_create(self, initial_value: T) -> Result<D, DynamicStorageOpenOrCreateError>;
}
pub trait DynamicStorage<T: Send + Sync>:
Sized + Debug + NamedConceptMgmt + NamedConcept + Send + Sync + Abandonable
{
type Builder<'builder>: DynamicStorageBuilder<'builder, T, Self>;
fn does_support_persistency() -> bool;
fn has_ownership(&self) -> bool;
fn release_ownership(&self);
fn acquire_ownership(&self);
fn get(&self) -> &T;
fn default_suffix() -> FileName {
unsafe { FileName::new_unchecked(b".dyn") }
}
#[doc(hidden)]
unsafe fn __internal_set_type_name_in_config(config: &mut Self::Configuration, type_name: &str);
}