dimas_core/builder_states.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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// Copyright © 2023 Stephan Kunz
//! Commonly used states for builders
#[doc(hidden)]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
// region: --- modules
use alloc::{string::String, sync::Arc};
use core::time::Duration;
#[cfg(feature = "std")]
use std::{collections::HashMap, sync::RwLock};
// endtregion: --- modules
// region: --- builder_states
/// State signaling that the builder has no storage value set
pub struct NoStorage;
/// State signaling that the builder has the storage value set
pub struct Storage<S>
where
S: Send + Sync + 'static,
{
/// Thread safe reference to a [`HashMap`] to store the created item of type T
pub storage: Arc<RwLock<HashMap<String, S>>>,
}
/// State signaling that the builder has no selector set
pub struct NoSelector;
/// State signaling that the builder has the selector set
pub struct Selector {
/// The selector
pub selector: String,
}
/// State signaling that the builder has no interval set
pub struct NoInterval;
/// State signaling that the builder has the interval set
pub struct Interval {
/// The [`Duration`] of the interval
pub interval: Duration,
}
/// State signaling that the builder has a callback not set
pub struct NoCallback;
/// State signaling that the builder has a callback set
pub struct Callback<C>
where
C: Send + Sync + 'static,
{
/// The callback to use
pub callback: C,
}
// endregion: --- builder_states