abi_stable/std_types/
option.rs

1//! Contains the ffi-safe equivalent of `std::option::Option`.
2
3use std::{mem, ops::Deref};
4
5use serde::{Deserialize, Deserializer, Serialize, Serializer};
6
7use crate::std_types::RResult;
8
9/// Ffi-safe equivalent of the `std::option::Option` type.
10///
11/// `Option` is also ffi-safe for NonNull/NonZero types, and references.
12///
13#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
14#[repr(u8)]
15#[derive(StableAbi)]
16// #[sabi(debug_print)]
17pub enum ROption<T> {
18    ///
19    RSome(T),
20    ///
21    RNone,
22}
23
24pub use self::ROption::*;
25
26#[allow(clippy::missing_const_for_fn)]
27impl<T> ROption<T> {
28    /// Converts from `ROption<T>` to `ROption<&T>`.
29    ///
30    /// # Example
31    ///
32    /// ```
33    /// # use abi_stable::std_types::*;
34    ///
35    /// assert_eq!(RSome(10).as_ref(), RSome(&10));
36    /// assert_eq!(RNone::<u32>.as_ref(), RNone);
37    ///
38    /// ```
39    #[inline]
40    pub const fn as_ref(&self) -> ROption<&T> {
41        match self {
42            RSome(v) => RSome(v),
43            RNone => RNone,
44        }
45    }
46
47    /// Converts from `ROption<T>` to `ROption<&mut T>`.
48    ///
49    /// # Example
50    ///
51    /// ```
52    /// # use abi_stable::std_types::*;
53    ///
54    /// assert_eq!(RSome(10).as_mut(), RSome(&mut 10));
55    /// assert_eq!(RNone::<u32>.as_mut(), RNone);
56    ///
57    /// ```
58    #[inline]
59    pub fn as_mut(&mut self) -> ROption<&mut T> {
60        match self {
61            RSome(v) => RSome(v),
62            RNone => RNone,
63        }
64    }
65
66    /// Returns whether `self` is an `RSome`
67    ///
68    /// # Example
69    ///
70    /// ```
71    /// # use abi_stable::std_types::*;
72    ///
73    /// assert_eq!(RSome(10).is_rsome(), true);
74    /// assert_eq!(RNone::<u32>.is_rsome(), false);
75    ///
76    /// ```
77    #[inline]
78    pub const fn is_rsome(&self) -> bool {
79        matches!(self, RSome { .. })
80    }
81
82    /// Returns whether `self` is an `RNone`
83    ///
84    /// # Example
85    ///
86    /// ```
87    /// # use abi_stable::std_types::*;
88    ///
89    /// assert_eq!(RSome(10).is_rnone(), false);
90    /// assert_eq!(RNone::<u32>.is_rnone(), true);
91    ///
92    /// ```
93    #[inline]
94    pub const fn is_rnone(&self) -> bool {
95        matches!(self, RNone { .. })
96    }
97
98    /// Returns whether `self` is an `RSome`
99    ///
100    /// # Example
101    ///
102    /// ```
103    /// # use abi_stable::std_types::*;
104    ///
105    /// assert_eq!(RSome(10).is_some(), true);
106    /// assert_eq!(RNone::<u32>.is_some(), false);
107    ///
108    /// ```
109    #[inline]
110    pub const fn is_some(&self) -> bool {
111        matches!(self, RSome { .. })
112    }
113
114    /// Returns whether `self` is an `RNone`
115    ///
116    /// # Example
117    ///
118    /// ```
119    /// # use abi_stable::std_types::*;
120    ///
121    /// assert_eq!(RSome(10).is_none(), false);
122    /// assert_eq!(RNone::<u32>.is_none(), true);
123    ///
124    /// ```
125    #[inline]
126    pub const fn is_none(&self) -> bool {
127        matches!(self, RNone { .. })
128    }
129
130    /// Converts from `ROption<T>` to `Option<T>`.
131    ///
132    /// # Example
133    ///
134    /// ```
135    /// # use abi_stable::std_types::*;
136    ///
137    /// assert_eq!(RSome(10).into_option(), Some(10));
138    /// assert_eq!(RNone::<u32>.into_option(), None);
139    ///
140    /// ```
141    #[inline]
142    pub fn into_option(self) -> Option<T> {
143        self.into()
144    }
145
146    /// Unwraps the `ROption<T>`, returning its contents.
147    ///
148    /// # Panics
149    ///
150    /// Panics if `self` is `RNone`, with the `msg` message.
151    ///
152    /// # Example
153    ///
154    /// ```
155    /// # use abi_stable::std_types::*;
156    ///
157    /// assert_eq!(RSome(100).expect("must contain a value"), 100);
158    ///
159    /// ```
160    ///
161    /// This one panics:
162    /// ```should_panic
163    /// # use abi_stable::std_types::*;
164    ///
165    /// let _ = RNone::<()>.expect("Oh noooo!");
166    /// ```
167    #[inline]
168    pub fn expect(self, msg: &str) -> T {
169        self.into_option().expect(msg)
170    }
171    /// Unwraps the ROption, returning its contents.
172    ///
173    /// # Panics
174    ///
175    /// Panics if `self` is `RNone`.
176    ///
177    /// # Example
178    ///
179    /// ```
180    /// # use abi_stable::std_types::*;
181    ///
182    /// assert_eq!(RSome(500).unwrap(), 500);
183    ///
184    /// ```
185    ///
186    /// This one panics:
187    /// ```should_panic
188    /// # use abi_stable::std_types::*;
189    ///
190    /// let _ = RNone::<()>.unwrap();
191    /// ```
192    #[inline]
193    pub fn unwrap(self) -> T {
194        self.into_option().unwrap()
195    }
196
197    /// Returns the value in the `ROption<T>`, or `def` if `self` is `RNone`.
198    ///
199    /// # Example
200    ///
201    /// ```
202    /// # use abi_stable::std_types::*;
203    ///
204    /// assert_eq!(RSome(10).unwrap_or(99), 10);
205    /// assert_eq!(RNone::<u32>.unwrap_or(99), 99);
206    ///
207    /// ```
208    #[inline]
209    pub fn unwrap_or(self, def: T) -> T {
210        match self {
211            RSome(x) => x,
212            RNone => def,
213        }
214    }
215
216    /// Returns the value in the `ROption<T>`, or `T::default()` if `self` is `RNone`.
217    ///
218    /// # Example
219    ///
220    /// ```
221    /// # use abi_stable::std_types::*;
222    ///
223    /// assert_eq!(RSome(10).unwrap_or_default(), 10);
224    /// assert_eq!(RNone::<u32>.unwrap_or_default(), 0);
225    ///
226    /// ```
227    #[inline]
228    pub fn unwrap_or_default(self) -> T
229    where
230        T: Default,
231    {
232        match self {
233            RSome(x) => x,
234            RNone => Default::default(),
235        }
236    }
237
238    /// Returns the value in the `ROption<T>`,
239    /// or the return value of calling `f` if `self` is `RNone`.
240    ///
241    /// # Example
242    ///
243    /// ```
244    /// # use abi_stable::std_types::*;
245    ///
246    /// assert_eq!(RSome(10).unwrap_or_else(|| 77), 10);
247    /// assert_eq!(RNone::<u32>.unwrap_or_else(|| 77), 77);
248    ///
249    /// ```
250    #[inline]
251    pub fn unwrap_or_else<F>(self, f: F) -> T
252    where
253        F: FnOnce() -> T,
254    {
255        match self {
256            RSome(x) => x,
257            RNone => f(),
258        }
259    }
260
261    /// Converts the `ROption<T>` to a `ROption<U>`,
262    /// transforming the contained value with the `f` closure.
263    ///
264    /// # Example
265    ///
266    /// ```
267    /// # use abi_stable::std_types::*;
268    ///
269    /// assert_eq!(RSome(10).map(|x| x * 2), RSome(20));
270    /// assert_eq!(RNone::<u32>.map(|x| x * 2), RNone);
271    ///
272    /// ```
273    #[inline]
274    pub fn map<U, F>(self, f: F) -> ROption<U>
275    where
276        F: FnOnce(T) -> U,
277    {
278        match self {
279            RSome(x) => RSome(f(x)),
280            RNone => RNone,
281        }
282    }
283
284    /// Transforms (and returns) the contained value with the `f` closure,
285    /// or returns `default` if `self` is `RNone`.
286    ///
287    /// # Example
288    ///
289    /// ```
290    /// # use abi_stable::std_types::*;
291    ///
292    /// assert_eq!(RSome(10).map_or(77, |x| x * 2), 20);
293    /// assert_eq!(RNone::<u32>.map_or(77, |x| x * 2), 77);
294    ///
295    /// ```
296    #[inline]
297    pub fn map_or<U, F>(self, default: U, f: F) -> U
298    where
299        F: FnOnce(T) -> U,
300    {
301        match self {
302            RSome(t) => f(t),
303            RNone => default,
304        }
305    }
306
307    /// Transforms (and returns) the contained value with the `f` closure,
308    /// or returns `otherwise()` if `self` is `RNone`..
309    ///
310    /// # Example
311    ///
312    /// ```
313    /// # use abi_stable::std_types::*;
314    ///
315    /// assert_eq!(RSome(10).map_or_else(|| 77, |x| x * 2), 20);
316    /// assert_eq!(RNone::<u32>.map_or_else(|| 77, |x| x * 2), 77);
317    ///
318    /// ```
319    #[inline]
320    pub fn map_or_else<U, D, F>(self, otherwise: D, f: F) -> U
321    where
322        D: FnOnce() -> U,
323        F: FnOnce(T) -> U,
324    {
325        match self {
326            RSome(t) => f(t),
327            RNone => otherwise(),
328        }
329    }
330
331    /// Transforms the `ROption<T>` into a `RResult<T, E>`, mapping `RSome(v)`
332    /// to `ROk(v)` and `RNone` to `RErr(err)`.
333    ///
334    /// Arguments passed to `ok_or` are eagerly evaluated; if you are passing the
335    /// result of a function call, it is recommended to use [`ok_or_else`], which is
336    /// lazily evaluated.
337    ///
338    /// [`ok_or_else`]: ROption::ok_or_else
339    ///
340    /// # Examples
341    ///
342    /// ```
343    /// # use abi_stable::std_types::*;
344    ///
345    /// let x = RSome("foo");
346    /// assert_eq!(x.ok_or(0), ROk("foo"));
347    ///
348    /// let x: ROption<&str> = RNone;
349    /// assert_eq!(x.ok_or(0), RErr(0));
350    /// ```
351    #[inline]
352    pub fn ok_or<E>(self, err: E) -> RResult<T, E> {
353        match self {
354            RSome(v) => RResult::ROk(v),
355            RNone => RResult::RErr(err),
356        }
357    }
358
359    /// Transforms the `ROption<T>` into a `RResult<T, E>`, mapping `RSome(v)` to
360    /// `ROk(v)` and `RNone` to `RErr(err())`.
361    ///
362    /// # Examples
363    ///
364    /// ```
365    /// # use abi_stable::std_types::*;
366    ///
367    /// let x = RSome("foo");
368    /// assert_eq!(x.ok_or_else(|| 0), ROk("foo"));
369    ///
370    /// let x: ROption<&str> = RNone;
371    /// assert_eq!(x.ok_or_else(|| 0), RErr(0));
372    /// ```
373    #[inline]
374    pub fn ok_or_else<E, F>(self, err: F) -> RResult<T, E>
375    where
376        F: FnOnce() -> E,
377    {
378        match self {
379            RSome(v) => RResult::ROk(v),
380            RNone => RResult::RErr(err()),
381        }
382    }
383
384    /// Returns `self` if `predicate(&self)` is true, otherwise returns `RNone`.
385    ///
386    /// # Example
387    ///
388    /// ```
389    /// # use abi_stable::std_types::*;
390    ///
391    /// assert_eq!(RSome(10).filter(|x| (x % 2) == 0), RSome(10));
392    /// assert_eq!(RSome(10).filter(|x| (x % 2) == 1), RNone);
393    /// assert_eq!(RNone::<u32>.filter(|_| true), RNone);
394    /// assert_eq!(RNone::<u32>.filter(|_| false), RNone);
395    ///
396    /// ```
397    pub fn filter<P>(self, predicate: P) -> Self
398    where
399        P: FnOnce(&T) -> bool,
400    {
401        if let RSome(x) = self {
402            if predicate(&x) {
403                return RSome(x);
404            }
405        }
406        RNone
407    }
408
409    /// Returns `self` if it is `RNone`, otherwise returns `optb`.
410    ///
411    /// # Example
412    ///
413    /// ```
414    /// # use abi_stable::std_types::*;
415    ///
416    /// assert_eq!(RSome(10).and(RSome(20)), RSome(20));
417    /// assert_eq!(RSome(10).and(RNone), RNone);
418    /// assert_eq!(RNone::<u32>.and(RSome(20)), RNone);
419    /// assert_eq!(RNone::<u32>.and(RNone), RNone);
420    ///
421    /// ```
422    #[inline]
423    pub fn and(self, optb: ROption<T>) -> ROption<T> {
424        match self {
425            RSome(_) => optb,
426            RNone => self,
427        }
428    }
429
430    /// Returns `self` if it is `RNone`,
431    /// otherwise returns the result of calling `f` with the value in `RSome`.
432    ///
433    /// # Example
434    ///
435    /// ```
436    /// # use abi_stable::std_types::*;
437    ///
438    /// assert_eq!(RSome(10).and_then(|x| RSome(x * 2)), RSome(20));
439    /// assert_eq!(RSome(10).and_then(|_| RNone::<u32>), RNone);
440    /// assert_eq!(RNone::<u32>.and_then(|x| RSome(x * 2)), RNone);
441    /// assert_eq!(RNone::<u32>.and_then(|_| RNone::<u32>), RNone);
442    ///
443    /// ```
444    #[inline]
445    pub fn and_then<F, U>(self, f: F) -> ROption<U>
446    where
447        F: FnOnce(T) -> ROption<U>,
448    {
449        match self {
450            RSome(x) => f(x),
451            RNone => RNone,
452        }
453    }
454
455    /// Returns `self` if it contains a value, otherwise returns `optb`.
456    ///
457    /// # Example
458    ///
459    /// ```
460    /// # use abi_stable::std_types::*;
461    ///
462    /// assert_eq!(RSome(10).or(RSome(20)), RSome(10));
463    /// assert_eq!(RSome(10).or(RNone    ), RSome(10));
464    /// assert_eq!(RNone::<u32>.or(RSome(20)), RSome(20));
465    /// assert_eq!(RNone::<u32>.or(RNone    ), RNone);
466    ///
467    /// ```
468    #[inline]
469    pub fn or(self, optb: ROption<T>) -> ROption<T> {
470        match self {
471            RSome(_) => self,
472            RNone => optb,
473        }
474    }
475
476    /// Returns `self` if it contains a value,
477    /// otherwise calls `optb` and returns the value it evaluates to.
478    ///
479    /// # Example
480    ///
481    /// ```
482    /// # use abi_stable::std_types::*;
483    ///
484    /// assert_eq!(RSome(10).or_else(|| RSome(20)), RSome(10));
485    /// assert_eq!(RSome(10).or_else(|| RNone), RSome(10));
486    /// assert_eq!(RNone::<u32>.or_else(|| RSome(20)), RSome(20));
487    /// assert_eq!(RNone::<u32>.or_else(|| RNone), RNone);
488    ///
489    /// ```
490    #[inline]
491    pub fn or_else<F>(self, f: F) -> ROption<T>
492    where
493        F: FnOnce() -> ROption<T>,
494    {
495        match self {
496            RSome(_) => self,
497            RNone => f(),
498        }
499    }
500
501    /// Returns `RNone` if both values are `RNone` or `RSome`,
502    /// otherwise returns the value that is an`RSome`.
503    ///
504    /// # Example
505    ///
506    /// ```
507    /// # use abi_stable::std_types::*;
508    ///
509    /// assert_eq!(RSome(10).xor(RSome(20)), RNone);
510    /// assert_eq!(RSome(10).xor(RNone), RSome(10));
511    /// assert_eq!(RNone::<u32>.xor(RSome(20)), RSome(20));
512    /// assert_eq!(RNone::<u32>.xor(RNone), RNone);
513    ///
514    /// ```
515    #[inline]
516    pub fn xor(self, optb: ROption<T>) -> ROption<T> {
517        match (self, optb) {
518            (RSome(a), RNone) => RSome(a),
519            (RNone, RSome(b)) => RSome(b),
520            _ => RNone,
521        }
522    }
523
524    /// Sets this ROption to `RSome(value)` if it was `RNone`.
525    /// Returns a mutable reference to the inserted/pre-existing `RSome`.
526    ///
527    /// # Example
528    ///
529    /// ```
530    /// # use abi_stable::std_types::*;
531    ///
532    /// assert_eq!(RSome(10).get_or_insert(40), &mut 10);
533    /// assert_eq!(RSome(20).get_or_insert(55), &mut 20);
534    /// assert_eq!(RNone::<u32>.get_or_insert(77), &mut 77);
535    ///
536    /// ```
537    #[inline]
538    pub fn get_or_insert(&mut self, value: T) -> &mut T {
539        if self.is_rnone() {
540            *self = RSome(value);
541        }
542
543        match *self {
544            RSome(ref mut v) => v,
545            RNone => unreachable!(),
546        }
547    }
548
549    /// Sets this `ROption` to `RSome(func())` if it was `RNone`.
550    /// Returns a mutable reference to the inserted/pre-existing `RSome`.
551    ///
552    /// # Example
553    ///
554    /// ```
555    /// # use abi_stable::std_types::*;
556    ///
557    /// assert_eq!(RSome(10).get_or_insert_with(|| 40), &mut 10);
558    /// assert_eq!(RSome(20).get_or_insert_with(|| 55), &mut 20);
559    /// assert_eq!(RNone::<u32>.get_or_insert_with(|| 77), &mut 77);
560    ///
561    /// ```
562    #[inline]
563    pub fn get_or_insert_with<F>(&mut self, func: F) -> &mut T
564    where
565        F: FnOnce() -> T,
566    {
567        if self.is_rnone() {
568            *self = RSome(func());
569        }
570
571        match *self {
572            RSome(ref mut v) => v,
573            RNone => unreachable!(),
574        }
575    }
576
577    /// Takes the value of `self`, replacing it with `RNone`
578    ///
579    /// # Example
580    ///
581    /// ```
582    /// # use abi_stable::std_types::*;
583    ///
584    /// let mut opt0 = RSome(10);
585    /// assert_eq!(opt0.take(), RSome(10));
586    /// assert_eq!(opt0, RNone);
587    ///
588    /// let mut opt1 = RSome(20);
589    /// assert_eq!(opt1.take(), RSome(20));
590    /// assert_eq!(opt1, RNone);
591    ///
592    /// let mut opt2 = RNone::<u32>;
593    /// assert_eq!(opt2.take(), RNone);
594    /// assert_eq!(opt2, RNone);
595    ///
596    /// ```
597    #[inline]
598    pub fn take(&mut self) -> ROption<T> {
599        mem::replace(self, RNone)
600    }
601
602    /// Replaces the value of `self` with `RSome(value)`.
603    ///
604    /// # Example
605    ///
606    /// ```
607    /// # use abi_stable::std_types::*;
608    ///
609    /// let mut opt0 = RSome(10);
610    /// assert_eq!(opt0.replace(55), RSome(10));
611    /// assert_eq!(opt0, RSome(55));
612    ///
613    /// let mut opt1 = RSome(20);
614    /// assert_eq!(opt1.replace(88), RSome(20));
615    /// assert_eq!(opt1, RSome(88));
616    ///
617    /// let mut opt2 = RNone::<u32>;
618    /// assert_eq!(opt2.replace(33), RNone);
619    /// assert_eq!(opt2, RSome(33));
620    ///
621    /// ```
622    #[inline]
623    pub fn replace(&mut self, value: T) -> ROption<T> {
624        mem::replace(self, RSome(value))
625    }
626}
627
628impl<T> ROption<&T> {
629    /// Converts an `ROption<&T>` to an `ROption<T>` by cloning its contents.
630    ///
631    /// # Example
632    ///
633    /// ```
634    /// # use abi_stable::std_types::*;
635    ///
636    /// assert_eq!(RSome(&vec![()]).cloned(), RSome(vec![()]));
637    /// assert_eq!(RNone::<&Vec<()>>.cloned(), RNone);
638    ///
639    /// ```
640    #[inline]
641    pub fn cloned(self) -> ROption<T>
642    where
643        T: Clone,
644    {
645        match self {
646            RSome(expr) => RSome(expr.clone()),
647            RNone => RNone,
648        }
649    }
650
651    /// Converts an `ROption<&T>` to an `ROption<T>` by Copy-ing its contents.
652    ///
653    /// # Example
654    ///
655    /// ```
656    /// # use abi_stable::std_types::*;
657    ///
658    /// assert_eq!(RSome(&7).copied(), RSome(7));
659    /// assert_eq!(RNone::<&u32>.copied(), RNone);
660    ///
661    /// ```
662    #[inline]
663    pub const fn copied(self) -> ROption<T>
664    where
665        T: Copy,
666    {
667        match self {
668            RSome(expr) => RSome(*expr),
669            RNone => RNone,
670        }
671    }
672}
673
674impl<T> ROption<&mut T> {
675    /// Converts an `ROption<&mut T>` to a `ROption<T>` by cloning its contents.
676    ///
677    /// # Example
678    ///
679    /// ```
680    /// # use abi_stable::std_types::*;
681    ///
682    /// assert_eq!(RSome(&mut vec![()]).cloned(), RSome(vec![()]));
683    /// assert_eq!(RNone::<&mut Vec<()>>.cloned(), RNone);
684    ///
685    /// ```
686    #[inline]
687    pub fn cloned(self) -> ROption<T>
688    where
689        T: Clone,
690    {
691        match self {
692            RSome(expr) => RSome(expr.clone()),
693            RNone => RNone,
694        }
695    }
696
697    /// Converts an `ROption<&mut T>` to a `ROption<T>` by Copy-ing its contents.
698    ///
699    /// # Example
700    ///
701    /// ```
702    /// # use abi_stable::std_types::*;
703    ///
704    /// assert_eq!(RSome(&mut 7).copied(), RSome(7));
705    /// assert_eq!(RNone::<&mut u32>.copied(), RNone);
706    ///
707    /// ```
708    #[inline]
709    pub fn copied(self) -> ROption<T>
710    where
711        T: Copy,
712    {
713        match self {
714            RSome(expr) => RSome(*expr),
715            RNone => RNone,
716        }
717    }
718}
719
720impl<T: Deref> ROption<T> {
721    /// Converts from `ROption<T>` (or `&ROption<T>`) to `ROption<&T::Target>`.
722    ///
723    /// Leaves the original ROption in-place, creating a new one with a
724    /// reference to the original one, additionally coercing the contents via
725    /// [`Deref`].
726    ///
727    /// # Examples
728    ///
729    /// ```
730    /// # use abi_stable::std_types::*;
731    ///
732    /// let x: ROption<RString> = RSome(RString::from("hey"));
733    /// assert_eq!(x.as_deref(), RSome("hey"));
734    ///
735    /// let x: ROption<RString> = RNone;
736    /// assert_eq!(x.as_deref(), RNone);
737    /// ```
738    pub fn as_deref(&self) -> ROption<&T::Target> {
739        self.as_ref().map(|t| t.deref())
740    }
741}
742
743/// The default value is `RNone`.
744impl<T> Default for ROption<T> {
745    fn default() -> Self {
746        RNone
747    }
748}
749
750impl_from_rust_repr! {
751    impl[T] From<Option<T>> for ROption<T> {
752        fn(this){
753            match this {
754                Some(v) => RSome(v),
755                None => RNone,
756            }
757        }
758    }
759}
760
761impl_into_rust_repr! {
762    impl[T] Into<Option<T>> for ROption<T> {
763        fn(this){
764            match this {
765                RSome(v) => Some(v),
766                RNone => None,
767            }
768        }
769    }
770}
771
772impl<'de, T> Deserialize<'de> for ROption<T>
773where
774    T: Deserialize<'de>,
775{
776    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
777    where
778        D: Deserializer<'de>,
779    {
780        Option::deserialize(deserializer).map(Self::from)
781    }
782}
783
784impl<T> Serialize for ROption<T>
785where
786    T: Serialize,
787{
788    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
789    where
790        S: Serializer,
791    {
792        self.as_ref().into_option().serialize(serializer)
793    }
794}
795
796/////////////////////////////////////////////////////////////////////
797
798#[cfg(all(test, not(feature = "only_new_tests")))]
799// #[cfg(test)]
800mod test {
801    use super::*;
802
803    #[test]
804    fn from_into() {
805        assert_eq!(ROption::from(Some(10)), RSome(10));
806        assert_eq!(ROption::from(None::<u32>), RNone);
807
808        assert_eq!(RSome(10).into_option(), Some(10));
809        assert_eq!(RNone::<u32>.into_option(), None);
810    }
811}