Skip to main content

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.
15#[inline]
16pub fn create<T: Value>(options: T) -> impl Options<T> {
17    OptionsWrapper(Ref::new(options))
18}
19
20struct OptionsWrapper<T: Value>(Ref<T>);
21
22impl<T: Value> Options<T> for OptionsWrapper<T> {
23    #[inline]
24    fn value(&self) -> Ref<T> {
25        self.0.clone()
26    }
27}