dimas_core/builder_states.rs
1// Copyright © 2023 Stephan Kunz
2
3//! Commonly used states for builders
4
5#[doc(hidden)]
6extern crate alloc;
7
8#[cfg(feature = "std")]
9extern crate std;
10
11// region: --- modules
12use alloc::{string::String, sync::Arc};
13use core::time::Duration;
14#[cfg(feature = "std")]
15use std::{collections::HashMap, sync::RwLock};
16// endtregion: --- modules
17
18// region: --- builder_states
19/// State signaling that the builder has no storage value set
20pub struct NoStorage;
21/// State signaling that the builder has the storage value set
22pub struct Storage<S>
23where
24 S: Send + Sync + 'static,
25{
26 /// Thread safe reference to a [`HashMap`] to store the created item of type T
27 pub storage: Arc<RwLock<HashMap<String, S>>>,
28}
29
30/// State signaling that the builder has no selector set
31pub struct NoSelector;
32/// State signaling that the builder has the selector set
33pub struct Selector {
34 /// The selector
35 pub selector: String,
36}
37
38/// State signaling that the builder has no interval set
39pub struct NoInterval;
40/// State signaling that the builder has the interval set
41pub struct Interval {
42 /// The [`Duration`] of the interval
43 pub interval: Duration,
44}
45
46/// State signaling that the builder has a callback not set
47pub struct NoCallback;
48/// State signaling that the builder has a callback set
49pub struct Callback<C>
50where
51 C: Send + Sync + 'static,
52{
53 /// The callback to use
54 pub callback: C,
55}
56// endregion: --- builder_states