1use crate::ctx::Context;
2use crate::ctx::Match;
3use crate::re::BoxedRegex;
4use crate::re::Regex;
5
6use std::cell::Cell;
7use std::cell::RefCell;
8use std::rc::Rc;
9use std::sync::Arc;
10use std::sync::Mutex;
11
12use super::ctor::BoxedCtor;
13use super::ctor::DynamicArcCtor;
14use super::ctor::DynamicBoxedCtor;
15use super::ctor::DynamicRcCtor;
16use super::Ctor;
17use super::DynamicArcRegex;
18use super::DynamicBoxedCtorSync;
19use super::DynamicBoxedRegex;
20use super::DynamicRcRegex;
21use super::WrappedTy;
22
23pub trait RegexIntoOp
24where
25 Self: Sized,
26{
27 fn into_box_regex(self) -> WrappedTy<BoxedRegex<Self>>;
28
29 fn into_rc_regex(self) -> WrappedTy<Rc<Self>>;
30
31 fn into_arc_regex(self) -> WrappedTy<Arc<Self>>;
32
33 fn into_cell_regex(self) -> WrappedTy<Cell<Self>>;
34
35 fn into_refcell_regex(self) -> WrappedTy<RefCell<Self>>;
36
37 fn into_mutex_regex(self) -> WrappedTy<Mutex<Self>>;
38
39 fn into_dyn_regex<'a, 'b, C>(
40 self,
41 ) -> WrappedTy<DynamicBoxedRegex<'b, C, <Self as Regex<C>>::Ret>>
42 where
43 C: Context<'a>,
44 Self: Regex<C> + 'b;
45
46 fn into_dyn_arc_regex<'a, 'b, C>(
47 self,
48 ) -> WrappedTy<DynamicArcRegex<'b, C, <Self as Regex<C>>::Ret>>
49 where
50 C: Context<'a>,
51 Self: Regex<C> + 'b;
52
53 fn into_dyn_rc_regex<'a, 'b, C>(
54 self,
55 ) -> WrappedTy<DynamicRcRegex<'b, C, <Self as Regex<C>>::Ret>>
56 where
57 C: Context<'a>,
58 Self: Regex<C> + 'b;
59}
60
61impl<T> RegexIntoOp for T {
62 fn into_box_regex(self) -> WrappedTy<BoxedRegex<Self>> {
63 WrappedTy {
64 value: BoxedRegex::new(self),
65 }
66 }
67
68 fn into_rc_regex(self) -> WrappedTy<Rc<Self>> {
69 WrappedTy::new(Rc::new(self))
70 }
71
72 fn into_arc_regex(self) -> WrappedTy<Arc<Self>> {
73 WrappedTy::new(Arc::new(self))
74 }
75
76 fn into_cell_regex(self) -> WrappedTy<Cell<Self>> {
77 WrappedTy::new(Cell::new(self))
78 }
79
80 fn into_refcell_regex(self) -> WrappedTy<RefCell<Self>> {
81 WrappedTy::new(RefCell::new(self))
82 }
83
84 fn into_mutex_regex(self) -> WrappedTy<Mutex<Self>> {
85 WrappedTy::new(Mutex::new(self))
86 }
87
88 fn into_dyn_regex<'a, 'b, C>(
89 self,
90 ) -> WrappedTy<DynamicBoxedRegex<'b, C, <Self as Regex<C>>::Ret>>
91 where
92 C: Context<'a>,
93 Self: Regex<C> + 'b,
94 {
95 WrappedTy {
96 value: DynamicBoxedRegex::new(self),
97 }
98 }
99
100 fn into_dyn_arc_regex<'a, 'b, C>(
101 self,
102 ) -> WrappedTy<DynamicArcRegex<'b, C, <Self as Regex<C>>::Ret>>
103 where
104 C: Context<'a>,
105 Self: Regex<C> + 'b,
106 {
107 WrappedTy {
108 value: DynamicArcRegex::new(self),
109 }
110 }
111
112 fn into_dyn_rc_regex<'a, 'b, C>(
113 self,
114 ) -> WrappedTy<DynamicRcRegex<'b, C, <Self as Regex<C>>::Ret>>
115 where
116 C: Context<'a>,
117 Self: Regex<C> + 'b,
118 {
119 WrappedTy {
120 value: DynamicRcRegex::new(self),
121 }
122 }
123}
124
125pub trait ConstructIntoOp
126where
127 Self: Sized,
128{
129 fn into_box(self) -> WrappedTy<BoxedCtor<Self>>;
130
131 fn into_rc(self) -> WrappedTy<Rc<Self>>;
132
133 fn into_arc(self) -> WrappedTy<Arc<Self>>;
134
135 fn into_cell(self) -> WrappedTy<Cell<Self>>;
136
137 fn into_refcell(self) -> WrappedTy<RefCell<Self>>;
138
139 fn into_mutex(self) -> WrappedTy<Mutex<Self>>;
140
141 fn into_dyn<'a, 'b, C, M, O, H, A>(self) -> WrappedTy<DynamicBoxedCtor<'a, 'b, C, M, O, H, A>>
142 where
143 C: Context<'a> + Match<C>,
144 Self: Ctor<'a, C, M, O, H, A> + 'b;
145
146 fn into_dyn_sync<'a, 'b, C, M, O, H, A>(
147 self,
148 ) -> WrappedTy<DynamicBoxedCtorSync<'a, 'b, C, M, O, H, A>>
149 where
150 C: Context<'a> + Match<C>,
151 Self: Ctor<'a, C, M, O, H, A> + Send + 'b;
152
153 fn into_dyn_arc<'a, 'b, C, M, O, H, A>(
154 self,
155 ) -> WrappedTy<DynamicArcCtor<'a, 'b, C, M, O, H, A>>
156 where
157 C: Context<'a> + Match<C>,
158 Self: Ctor<'a, C, M, O, H, A> + 'b;
159
160 fn into_dyn_rc<'a, 'b, C, M, O, H, A>(self) -> WrappedTy<DynamicRcCtor<'a, 'b, C, M, O, H, A>>
161 where
162 C: Context<'a> + Match<C>,
163 Self: Ctor<'a, C, M, O, H, A> + 'b;
164}
165
166impl<T> ConstructIntoOp for T
167where
168 Self: Sized,
169{
170 fn into_box(self) -> WrappedTy<BoxedCtor<Self>> {
195 WrappedTy::new(Box::new(self))
196 }
197
198 fn into_rc(self) -> WrappedTy<Rc<Self>> {
226 WrappedTy::new(Rc::new(self))
227 }
228
229 fn into_arc(self) -> WrappedTy<Arc<Self>> {
230 WrappedTy::new(Arc::new(self))
231 }
232
233 fn into_cell(self) -> WrappedTy<Cell<Self>> {
234 WrappedTy::new(Cell::new(self))
235 }
236
237 fn into_refcell(self) -> WrappedTy<RefCell<Self>> {
238 WrappedTy::new(RefCell::new(self))
239 }
240
241 fn into_mutex(self) -> WrappedTy<Mutex<Self>> {
242 WrappedTy::new(Mutex::new(self))
243 }
244
245 fn into_dyn<'a, 'b, C, M, O, H, A>(self) -> WrappedTy<DynamicBoxedCtor<'a, 'b, C, M, O, H, A>>
266 where
267 C: Context<'a> + Match<C>,
268 Self: Ctor<'a, C, M, O, H, A> + 'b,
269 {
270 WrappedTy {
271 value: DynamicBoxedCtor::new(self),
272 }
273 }
274
275 fn into_dyn_sync<'a, 'b, C, M, O, H, A>(
276 self,
277 ) -> WrappedTy<DynamicBoxedCtorSync<'a, 'b, C, M, O, H, A>>
278 where
279 C: Context<'a> + Match<C>,
280 Self: Ctor<'a, C, M, O, H, A> + Send + 'b,
281 {
282 WrappedTy {
283 value: DynamicBoxedCtorSync::new(self),
284 }
285 }
286
287 fn into_dyn_arc<'a, 'b, C, M, O, H, A>(self) -> WrappedTy<DynamicArcCtor<'a, 'b, C, M, O, H, A>>
288 where
289 C: Context<'a> + Match<C>,
290 Self: Ctor<'a, C, M, O, H, A> + 'b,
291 {
292 WrappedTy {
293 value: DynamicArcCtor::new(self),
294 }
295 }
296
297 fn into_dyn_rc<'a, 'b, C, M, O, H, A>(self) -> WrappedTy<DynamicRcCtor<'a, 'b, C, M, O, H, A>>
298 where
299 C: Context<'a> + Match<C>,
300 Self: Ctor<'a, C, M, O, H, A> + 'b,
301 {
302 WrappedTy {
303 value: DynamicRcCtor::new(self),
304 }
305 }
306}