1use std::rc::Rc;
2
3pub trait IntoRc<T: ?Sized> {
4 fn into_rc(self) -> Rc<T>;
5}
6
7impl<T: ?Sized> IntoRc<T> for Rc<T> {
8 fn into_rc(self) -> Rc<T> {
9 self
10 }
11}
12
13impl<T: ?Sized> IntoRc<T> for &Rc<T> {
14 fn into_rc(self) -> Rc<T> {
15 Rc::clone(self)
16 }
17}
18
19impl<T> IntoRc<T> for T {
20 fn into_rc(self) -> Rc<T> {
21 Rc::new(self)
22 }
23}
24
25pub trait TakeRc<T: ?Sized> {
26 fn take_rc(self) -> Rc<T>;
27}
28
29impl<T: ?Sized, R: IntoRc<T>, F: FnOnce() -> R> TakeRc<T> for F {
30 fn take_rc(self) -> Rc<T> {
31 self().into_rc()
32 }
33}
34
35impl<T: ?Sized> TakeRc<T> for Rc<T> {
36 fn take_rc(self) -> Rc<T> {
37 self
38 }
39}
40
41pub trait IntoOptionalRc<T: ?Sized> {
61 fn into_optional_rc(self) -> Option<Rc<T>>;
62}
63
64impl<T: ?Sized> IntoOptionalRc<T> for Rc<T> {
65 fn into_optional_rc(self) -> Option<Rc<T>> {
66 Some(self)
67 }
68}
69
70impl<T> IntoOptionalRc<T> for Option<T> {
71 fn into_optional_rc(self) -> Option<Rc<T>> {
72 self.map(|v| Rc::new(v))
73 }
74}
75
76impl<T: ?Sized> IntoOptionalRc<T> for Option<Rc<T>> {
77 fn into_optional_rc(self) -> Option<Rc<T>> {
78 self
79 }
80}
81
82impl<T> IntoOptionalRc<T> for T {
83 fn into_optional_rc(self) -> Option<Rc<T>> {
84 Some(Rc::new(self))
85 }
86}