orx_concurrent_option/into_option.rs
1use crate::ConcurrentOption;
2
3/// Trait representing types that can be converted into a standard Option.
4///
5/// # Examples
6///
7/// ```rust
8/// use orx_concurrent_option::*;
9///
10/// let con_option: ConcurrentOption<i32> = ConcurrentOption::some(42);
11/// assert_eq!(con_option.into_option(), Some(42));
12///
13/// let option: Option<i32> = Some(42);
14/// assert_eq!(option.into_option(), Some(42));
15/// ```
16pub trait IntoOption<T> {
17 /// Converts self into Option.
18 ///
19 /// # Examples
20 ///
21 /// ```rust
22 /// use orx_concurrent_option::*;
23 ///
24 /// let con_option: ConcurrentOption<i32> = ConcurrentOption::some(42);
25 /// assert_eq!(con_option.into_option(), Some(42));
26 ///
27 /// let option: Option<i32> = Some(42);
28 /// assert_eq!(option.into_option(), Some(42));
29 /// ```
30 fn into_option(self) -> Option<T>;
31}
32
33impl<T> IntoOption<T> for Option<T> {
34 fn into_option(self) -> Option<T> {
35 self
36 }
37}
38
39impl<T> IntoOption<T> for ConcurrentOption<T> {
40 fn into_option(mut self) -> Option<T> {
41 self.exclusive_take()
42 }
43}