options/
option.rs

1use crate::{Ref, Value};
2
3/// Defines the behavior to retrieve configured options.
4#[cfg_attr(feature = "async", maybe_impl::traits(Send, Sync))]
5pub trait Options<T: Value> {
6    /// Gets the configured value.
7    fn value(&self) -> Ref<T>;
8}
9
10/// Creates a wrapper around a value to return itself as [`Options`](Options).
11///
12/// # Arguments
13///
14/// * `options` - The options value to wrap.
15pub fn create<T: Value>(options: T) -> impl Options<T> {
16    OptionsWrapper(Ref::new(options))
17}
18
19struct OptionsWrapper<T: Value>(Ref<T>);
20
21impl<T: Value> Options<T> for OptionsWrapper<T> {
22    fn value(&self) -> Ref<T> {
23        self.0.clone()
24    }
25}
26
27unsafe impl<T: Send + Sync> Send for OptionsWrapper<T> {}
28unsafe impl<T: Send + Sync> Sync for OptionsWrapper<T> {}