1#[fp_macros::document_module]
6mod inner {
7 use {
8 crate::{
9 classes::{
10 Monoid,
11 Semigroup,
12 SendCloneableFn,
13 },
14 functions::identity,
15 },
16 fp_macros::*,
17 std::{
18 fmt::{
19 self,
20 Debug,
21 Formatter,
22 },
23 hash::Hash,
24 },
25 };
26
27 #[document_type_parameters(
38 "The lifetime of the function and its captured data.",
39 "The brand of the thread-safe cloneable function wrapper.",
40 "The input and output type of the function."
41 )]
42 #[document_fields("The wrapped thread-safe function.")]
44 pub struct SendEndofunction<'a, FnBrand: SendCloneableFn, A: 'a>(
46 pub <FnBrand as SendCloneableFn>::SendOf<'a, A, A>,
47 );
48
49 #[document_type_parameters(
50 "The lifetime of the function and its captured data.",
51 "The brand of the thread-safe cloneable function wrapper.",
52 "The input and output type of the function."
53 )]
54 impl<'a, FnBrand: SendCloneableFn, A: 'a> SendEndofunction<'a, FnBrand, A> {
55 #[document_signature]
59 #[document_parameters("The function to wrap.")]
61 #[document_returns("A new `SendEndofunction`.")]
63 #[document_examples]
65 pub fn new(f: <FnBrand as SendCloneableFn>::SendOf<'a, A, A>) -> Self {
79 Self(f)
80 }
81 }
82
83 #[document_type_parameters(
84 "The lifetime of the function and its captured data.",
85 "The brand of the thread-safe cloneable function wrapper.",
86 "The input and output type of the function."
87 )]
88 #[document_parameters("The function to clone.")]
89 impl<'a, FnBrand: SendCloneableFn, A: 'a> Clone for SendEndofunction<'a, FnBrand, A> {
90 #[document_signature]
91 #[document_returns("A new `SendEndofunction` instance that is a copy of the original.")]
92 #[document_examples]
93 fn clone(&self) -> Self {
107 Self::new(self.0.clone())
108 }
109 }
110
111 #[document_type_parameters(
112 "The lifetime of the function and its captured data.",
113 "The brand of the thread-safe cloneable function wrapper.",
114 "The input and output type of the function."
115 )]
116 #[document_parameters("The function to format.")]
117 impl<'a, FnBrand: SendCloneableFn, A: 'a> Debug for SendEndofunction<'a, FnBrand, A>
118 where
119 <FnBrand as SendCloneableFn>::SendOf<'a, A, A>: Debug,
120 {
121 #[document_signature]
122 #[document_parameters("The formatter to use.")]
123 #[document_returns("The result of the formatting operation.")]
124 #[document_examples]
125 fn fmt(
140 &self,
141 fmt: &mut Formatter<'_>,
142 ) -> fmt::Result {
143 fmt.debug_tuple("SendEndofunction").field(&self.0).finish()
144 }
145 }
146
147 #[document_type_parameters(
148 "The lifetime of the function and its captured data.",
149 "The brand of the thread-safe cloneable function wrapper.",
150 "The input and output type of the function."
151 )]
152 impl<'a, FnBrand: SendCloneableFn, A: 'a> Eq for SendEndofunction<'a, FnBrand, A> where
153 <FnBrand as SendCloneableFn>::SendOf<'a, A, A>: Eq
154 {
155 }
156
157 #[document_type_parameters(
158 "The lifetime of the function and its captured data.",
159 "The brand of the thread-safe cloneable function wrapper.",
160 "The input and output type of the function."
161 )]
162 #[document_parameters("The function to hash.")]
163 impl<'a, FnBrand: SendCloneableFn, A: 'a> Hash for SendEndofunction<'a, FnBrand, A>
164 where
165 <FnBrand as SendCloneableFn>::SendOf<'a, A, A>: Hash,
166 {
167 #[document_signature]
168 #[document_type_parameters("The type of the hasher.")]
169 #[document_parameters("The hasher state to update.")]
170 #[document_examples]
171 fn hash<H: std::hash::Hasher>(
186 &self,
187 state: &mut H,
188 ) {
189 self.0.hash(state);
190 }
191 }
192
193 #[document_type_parameters(
194 "The lifetime of the function and its captured data.",
195 "The brand of the thread-safe cloneable function wrapper.",
196 "The input and output type of the function."
197 )]
198 #[document_parameters("The function to compare.")]
199 impl<'a, FnBrand: SendCloneableFn, A: 'a> Ord for SendEndofunction<'a, FnBrand, A>
200 where
201 <FnBrand as SendCloneableFn>::SendOf<'a, A, A>: Ord,
202 {
203 #[document_signature]
204 #[document_parameters("The other function to compare to.")]
205 #[document_returns("The ordering of the values.")]
206 #[document_examples]
207 fn cmp(
225 &self,
226 other: &Self,
227 ) -> std::cmp::Ordering {
228 self.0.cmp(&other.0)
229 }
230 }
231
232 #[document_type_parameters(
233 "The lifetime of the function and its captured data.",
234 "The brand of the thread-safe cloneable function wrapper.",
235 "The input and output type of the function."
236 )]
237 #[document_parameters("The function to compare.")]
238 impl<'a, FnBrand: SendCloneableFn, A: 'a> PartialEq for SendEndofunction<'a, FnBrand, A>
239 where
240 <FnBrand as SendCloneableFn>::SendOf<'a, A, A>: PartialEq,
241 {
242 #[document_signature]
243 #[document_parameters("The other function to compare to.")]
244 #[document_returns("True if the values are equal, false otherwise.")]
245 #[document_examples]
246 fn eq(
264 &self,
265 other: &Self,
266 ) -> bool {
267 self.0 == other.0
268 }
269 }
270
271 #[document_type_parameters(
272 "The lifetime of the function and its captured data.",
273 "The brand of the thread-safe cloneable function wrapper.",
274 "The input and output type of the function."
275 )]
276 #[document_parameters("The function to compare.")]
277 impl<'a, FnBrand: SendCloneableFn, A: 'a> PartialOrd for SendEndofunction<'a, FnBrand, A>
278 where
279 <FnBrand as SendCloneableFn>::SendOf<'a, A, A>: PartialOrd,
280 {
281 #[document_signature]
282 #[document_parameters("The other function to compare to.")]
283 #[document_returns("An ordering if the values can be compared, none otherwise.")]
284 #[document_examples]
285 fn partial_cmp(
303 &self,
304 other: &Self,
305 ) -> Option<std::cmp::Ordering> {
306 self.0.partial_cmp(&other.0)
307 }
308 }
309
310 #[document_type_parameters(
311 "The lifetime of the function and its captured data.",
312 "The brand of the thread-safe cloneable function wrapper.",
313 "The input and output type of the function."
314 )]
315 impl<'a, FnBrand: 'a + SendCloneableFn, A: 'a + Send + Sync> Semigroup
316 for SendEndofunction<'a, FnBrand, A>
317 {
318 #[document_signature]
324 #[document_parameters(
326 "The second function to apply (the outer function).",
327 "The first function to apply (the inner function)."
328 )]
329 #[document_returns("The composed function `a . b`.")]
331 #[document_examples]
332 fn append(
352 a: Self,
353 b: Self,
354 ) -> Self {
355 let f = a.0;
356 let g = b.0;
357 Self::new(<FnBrand as SendCloneableFn>::send_cloneable_fn_new(move |x| f(g(x))))
359 }
360 }
361
362 #[document_type_parameters(
363 "The lifetime of the function and its captured data.",
364 "The brand of the thread-safe cloneable function wrapper.",
365 "The input and output type of the function."
366 )]
367 impl<'a, FnBrand: 'a + SendCloneableFn, A: 'a + Send + Sync> Monoid
368 for SendEndofunction<'a, FnBrand, A>
369 {
370 #[document_signature]
374 #[document_returns("The identity endofunction.")]
376 #[document_examples]
378 fn empty() -> Self {
390 Self::new(<FnBrand as SendCloneableFn>::send_cloneable_fn_new(identity))
391 }
392 }
393}
394
395pub use inner::*;