1#[fp_macros::document_module]
32pub(crate) mod inner {
33 use {
34 crate::{
35 brands::OptionBrand,
36 classes::{
37 Compactable,
38 RefCompactable,
39 },
40 dispatch::{
41 Ref,
42 Val,
43 },
44 kinds::*,
45 },
46 fp_macros::*,
47 };
48
49 #[document_type_parameters(
57 "The lifetime of the values.",
58 "The brand of the compactable.",
59 "The type of the value(s) inside the `Option` wrappers.",
60 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
61 )]
62 #[document_parameters("The container implementing this dispatch.")]
63 pub trait CompactDispatch<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, Marker> {
64 #[document_signature]
66 #[document_returns(
68 "A new container with `None` values removed and `Some` values unwrapped."
69 )]
70 #[document_examples]
71 fn dispatch(self) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>);
82 }
83
84 #[document_type_parameters(
86 "The lifetime of the values.",
87 "The brand of the compactable.",
88 "The type of the value(s) inside the `Option` wrappers."
89 )]
90 #[document_parameters("The owned container of `Option` values.")]
91 impl<'a, Brand, A> CompactDispatch<'a, Brand, A, Val> for Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<OptionBrand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)>)
92 where
93 Brand: Compactable,
94 A: 'a,
95 {
96 #[document_signature]
97 #[document_returns(
99 "A new container with `None` values removed and `Some` values unwrapped."
100 )]
101 #[document_examples]
102 fn dispatch(self) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>) {
113 Brand::compact(self)
114 }
115 }
116
117 #[document_type_parameters(
119 "The lifetime of the values.",
120 "The brand of the compactable.",
121 "The type of the value(s) inside the `Option` wrappers."
122 )]
123 #[document_parameters("The borrowed container of `Option` values.")]
124 impl<'a, Brand, A> CompactDispatch<'a, Brand, A, Ref> for &Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<OptionBrand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)>)
125 where
126 Brand: RefCompactable,
127 A: 'a + Clone,
128 {
129 #[document_signature]
130 #[document_returns(
132 "A new container with `None` values removed and `Some` values unwrapped."
133 )]
134 #[document_examples]
135 fn dispatch(self) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>) {
147 Brand::ref_compact(self)
148 }
149 }
150
151 #[document_type_parameters(
159 "The lifetime of the values.",
160 "The brand of the compactable.",
161 "The error type inside the `Result` wrappers.",
162 "The success type inside the `Result` wrappers.",
163 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
164 )]
165 #[document_parameters("The container implementing this dispatch.")]
166 pub trait SeparateDispatch<'a, Brand: Kind_cdc7cd43dac7585f, E: 'a, O: 'a, Marker> {
167 #[document_signature]
169 #[document_returns("A tuple of two containers: `Err` values and `Ok` values.")]
171 #[document_examples]
172 fn dispatch(
184 self
185 ) -> (
186 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
187 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
188 );
189 }
190
191 #[document_type_parameters(
193 "The lifetime of the values.",
194 "The brand of the compactable.",
195 "The error type inside the `Result` wrappers.",
196 "The success type inside the `Result` wrappers."
197 )]
198 #[document_parameters("The owned container of `Result` values.")]
199 impl<'a, Brand, E, O> SeparateDispatch<'a, Brand, E, O, Val> for Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>)
200 where
201 Brand: Compactable,
202 E: 'a,
203 O: 'a,
204 {
205 #[document_signature]
206 #[document_returns("A tuple of two containers: `Err` values and `Ok` values.")]
208 #[document_examples]
209 fn dispatch(
221 self
222 ) -> (
223 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
224 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
225 ) {
226 Brand::separate(self)
227 }
228 }
229
230 #[document_type_parameters(
232 "The lifetime of the values.",
233 "The brand of the compactable.",
234 "The error type inside the `Result` wrappers.",
235 "The success type inside the `Result` wrappers."
236 )]
237 #[document_parameters("The borrowed container of `Result` values.")]
238 impl<'a, Brand, E, O> SeparateDispatch<'a, Brand, E, O, Ref> for &Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>)
239 where
240 Brand: RefCompactable,
241 E: 'a + Clone,
242 O: 'a + Clone,
243 {
244 #[document_signature]
245 #[document_returns("A tuple of two containers: `Err` values and `Ok` values.")]
247 #[document_examples]
248 fn dispatch(
261 self
262 ) -> (
263 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
264 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
265 ) {
266 Brand::ref_separate(self)
267 }
268 }
269
270 #[document_signature]
281 #[document_type_parameters(
283 "The lifetime of the values.",
284 "The container type (owned or borrowed). Brand is inferred from this.",
285 "The type of the value(s) inside the `Option` wrappers.",
286 "The brand, inferred via InferableBrand from FA and the element type."
287 )]
288 #[document_parameters("The container of `Option` values (owned or borrowed).")]
290 #[document_returns("A new container with `None` values removed and `Some` values unwrapped.")]
292 #[document_examples]
293 pub fn compact<'a, FA, A: 'a, Brand>(fa: FA) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
303 where
304 Brand: Kind_cdc7cd43dac7585f,
305 FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, Option<A>>
306 + CompactDispatch<
307 'a,
308 Brand,
309 A,
310 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, Option<A>>>::Marker,
311 >, {
312 fa.dispatch()
313 }
314
315 #[document_signature]
324 #[document_type_parameters(
326 "The lifetime of the values.",
327 "The container type (owned or borrowed). Brand is inferred from this.",
328 "The error type inside the `Result` wrappers.",
329 "The success type inside the `Result` wrappers.",
330 "The brand, inferred via InferableBrand from FA and the element type."
331 )]
332 #[document_parameters("The container of `Result` values (owned or borrowed).")]
334 #[document_returns("A tuple of two containers: `Err` values and `Ok` values.")]
336 #[document_examples]
337 pub fn separate<'a, FA, E: 'a, O: 'a, Brand>(
346 fa: FA
347 ) -> (<Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>)
348 where
349 Brand: Kind_cdc7cd43dac7585f,
350 FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, Result<O, E>>
351 + SeparateDispatch<
352 'a,
353 Brand,
354 E,
355 O,
356 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, Result<O, E>>>::Marker,
357 >, {
358 fa.dispatch()
359 }
360
361 pub mod explicit {
368 use super::*;
369
370 #[document_signature]
377 #[document_type_parameters(
379 "The lifetime of the values.",
380 "The brand of the compactable.",
381 "The type of the value(s) inside the `Option` wrappers.",
382 "The container type (owned or borrowed), inferred from the argument.",
383 "Dispatch marker type, inferred automatically."
384 )]
385 #[document_parameters("The container of `Option` values (owned or borrowed).")]
387 #[document_returns(
389 "A new container with `None` values removed and `Some` values unwrapped."
390 )]
391 #[document_examples]
393 #[allow_named_generics]
410 pub fn compact<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, FA, Marker>(
411 fa: FA
412 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
413 where
414 FA: CompactDispatch<'a, Brand, A, Marker>, {
415 fa.dispatch()
416 }
417
418 #[document_signature]
425 #[document_type_parameters(
427 "The lifetime of the values.",
428 "The brand of the compactable.",
429 "The error type inside the `Result` wrappers.",
430 "The success type inside the `Result` wrappers.",
431 "The container type (owned or borrowed), inferred from the argument.",
432 "Dispatch marker type, inferred automatically."
433 )]
434 #[document_parameters("The container of `Result` values (owned or borrowed).")]
436 #[document_returns("A tuple of two containers: `Err` values and `Ok` values.")]
438 #[document_examples]
440 #[allow_named_generics]
459 pub fn separate<'a, Brand: Kind_cdc7cd43dac7585f, E: 'a, O: 'a, FA, Marker>(
460 fa: FA
461 ) -> (
462 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
463 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
464 )
465 where
466 FA: SeparateDispatch<'a, Brand, E, O, Marker>, {
467 fa.dispatch()
468 }
469 }
470}
471
472pub use inner::*;