1#[fp_macros::document_module]
26pub(crate) mod inner {
27 use {
28 crate::{
29 classes::{
30 Alt,
31 RefAlt,
32 },
33 dispatch::{
34 Ref,
35 Val,
36 },
37 kinds::*,
38 },
39 fp_macros::*,
40 };
41
42 #[document_type_parameters(
48 "The lifetime of the values.",
49 "The brand of the functor.",
50 "The type of the value(s) inside the functor.",
51 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
52 )]
53 #[document_parameters("The container implementing this dispatch.")]
54 pub trait AltDispatch<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a + Clone, Marker> {
55 #[document_signature]
57 #[document_parameters("The other container to combine with.")]
59 #[document_returns("A new container from the combination of both inputs.")]
61 #[document_examples]
62 fn dispatch(
73 self,
74 other: Self,
75 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>);
76 }
77
78 #[document_type_parameters(
82 "The lifetime of the values.",
83 "The brand of the functor.",
84 "The type of the value(s) inside the functor."
85 )]
86 #[document_parameters("The owned container.")]
87 impl<'a, Brand, A> AltDispatch<'a, Brand, A, Val> for Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
88 where
89 Brand: Alt,
90 A: 'a + Clone,
91 {
92 #[document_signature]
93 #[document_parameters("The other container to combine with.")]
95 #[document_returns("A new container from the combination of both inputs.")]
97 #[document_examples]
98 fn dispatch(
109 self,
110 other: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
111 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>) {
112 Brand::alt(self, other)
113 }
114 }
115
116 #[document_type_parameters(
120 "The lifetime of the values.",
121 "The brand of the functor.",
122 "The type of the value(s) inside the functor."
123 )]
124 #[document_parameters("The borrowed container.")]
125 impl<'a, Brand, A> AltDispatch<'a, Brand, A, Ref> for &Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
126 where
127 Brand: RefAlt,
128 A: 'a + Clone,
129 {
130 #[document_signature]
131 #[document_parameters("The other borrowed container to combine with.")]
133 #[document_returns("A new container from the combination of both inputs.")]
135 #[document_examples]
136 fn dispatch(
149 self,
150 other: &Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
151 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>) {
152 Brand::ref_alt(self, other)
153 }
154 }
155
156 #[document_signature]
166 #[document_type_parameters(
168 "The lifetime of the values.",
169 "The container type (owned or borrowed). Brand is inferred from this.",
170 "The type of the value(s) inside the functor.",
171 "The brand, inferred via InferableBrand from FA and the element type."
172 )]
173 #[document_parameters(
175 "The first container (owned or borrowed).",
176 "The second container (same ownership as the first)."
177 )]
178 #[document_returns("A new container from the combination of both inputs.")]
180 #[document_examples]
181 pub fn alt<'a, FA, A: 'a + Clone, Brand>(
192 fa1: FA,
193 fa2: FA,
194 ) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
195 where
196 Brand: Kind_cdc7cd43dac7585f,
197 FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>
198 + AltDispatch<'a, Brand, A, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>, {
199 fa1.dispatch(fa2)
200 }
201
202 pub mod explicit {
209 use super::*;
210
211 #[document_signature]
222 #[document_type_parameters(
224 "The lifetime of the values.",
225 "The brand of the functor.",
226 "The type of the value(s) inside the functor.",
227 "The container type (owned or borrowed), inferred from the argument.",
228 "Dispatch marker type, inferred automatically."
229 )]
230 #[document_parameters("The first container.", "The second container.")]
232 #[document_returns("A new container from the combination of both inputs.")]
234 #[document_examples]
236 pub fn alt<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a + Clone, FA, Marker>(
254 fa1: FA,
255 fa2: FA,
256 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
257 where
258 FA: AltDispatch<'a, Brand, A, Marker>, {
259 fa1.dispatch(fa2)
260 }
261 }
262}
263
264pub use inner::*;