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 "Dispatch marker type, inferred automatically."
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, Marker>(
303 fa: FA
304 ) -> <<FA as InferableBrand_cdc7cd43dac7585f>::Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
305 where
306 FA: InferableBrand_cdc7cd43dac7585f
307 + CompactDispatch<'a, <FA as InferableBrand_cdc7cd43dac7585f>::Brand, A, Marker>, {
308 fa.dispatch()
309 }
310
311 #[document_signature]
320 #[document_type_parameters(
322 "The lifetime of the values.",
323 "The container type (owned or borrowed). Brand is inferred from this.",
324 "The error type inside the `Result` wrappers.",
325 "The success type inside the `Result` wrappers.",
326 "Dispatch marker type, inferred automatically."
327 )]
328 #[document_parameters("The container of `Result` values (owned or borrowed).")]
330 #[document_returns("A tuple of two containers: `Err` values and `Ok` values.")]
332 #[document_examples]
333 pub fn separate<'a, FA, E: 'a, O: 'a, Marker>(
342 fa: FA
343 ) -> (
344 <<FA as InferableBrand_cdc7cd43dac7585f>::Brand as Kind_cdc7cd43dac7585f>::Of<'a, E>,
345 <<FA as InferableBrand_cdc7cd43dac7585f>::Brand as Kind_cdc7cd43dac7585f>::Of<'a, O>,
346 )
347 where
348 FA: InferableBrand_cdc7cd43dac7585f
349 + SeparateDispatch<'a, <FA as InferableBrand_cdc7cd43dac7585f>::Brand, E, O, Marker>, {
350 fa.dispatch()
351 }
352
353 pub mod explicit {
360 use super::*;
361
362 #[document_signature]
369 #[document_type_parameters(
371 "The lifetime of the values.",
372 "The brand of the compactable.",
373 "The type of the value(s) inside the `Option` wrappers.",
374 "The container type (owned or borrowed), inferred from the argument.",
375 "Dispatch marker type, inferred automatically."
376 )]
377 #[document_parameters("The container of `Option` values (owned or borrowed).")]
379 #[document_returns(
381 "A new container with `None` values removed and `Some` values unwrapped."
382 )]
383 #[document_examples]
385 #[allow_named_generics]
402 pub fn compact<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, FA, Marker>(
403 fa: FA
404 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
405 where
406 FA: CompactDispatch<'a, Brand, A, Marker>, {
407 fa.dispatch()
408 }
409
410 #[document_signature]
417 #[document_type_parameters(
419 "The lifetime of the values.",
420 "The brand of the compactable.",
421 "The error type inside the `Result` wrappers.",
422 "The success type inside the `Result` wrappers.",
423 "The container type (owned or borrowed), inferred from the argument.",
424 "Dispatch marker type, inferred automatically."
425 )]
426 #[document_parameters("The container of `Result` values (owned or borrowed).")]
428 #[document_returns("A tuple of two containers: `Err` values and `Ok` values.")]
430 #[document_examples]
432 #[allow_named_generics]
451 pub fn separate<'a, Brand: Kind_cdc7cd43dac7585f, E: 'a, O: 'a, FA, Marker>(
452 fa: FA
453 ) -> (
454 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
455 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
456 )
457 where
458 FA: SeparateDispatch<'a, Brand, E, O, Marker>, {
459 fa.dispatch()
460 }
461 }
462}
463
464pub use inner::*;