fn_traits/fns/
convert_identity_fn.rs1use crate::{Fn, FnMut, FnOnce};
2use core::convert;
3use core::marker::PhantomData;
4
5#[derive(Clone, Copy, Default)]
7pub struct ConvertIdentityFn {
8 _phantom: PhantomData<()>,
9}
10
11impl<T> FnOnce<(T,)> for ConvertIdentityFn {
12 type Output = T;
13
14 fn call_once(self, args: (T,)) -> Self::Output {
15 convert::identity(args.0)
16 }
17}
18
19impl<T> FnMut<(T,)> for ConvertIdentityFn {
20 type Output = T;
21
22 fn call_mut(&mut self, args: (T,)) -> Self::Output {
23 self.call_once(args)
24 }
25}
26
27impl<T> Fn<(T,)> for ConvertIdentityFn {
28 type Output = T;
29
30 fn call(&self, args: (T,)) -> Self::Output {
31 self.call_once(args)
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::super::tests::{into_std_fn, into_std_fn_mut, into_std_fn_once};
38 use super::ConvertIdentityFn;
39
40 #[test]
41 fn test_convert_identity_fn() {
42 let f = ConvertIdentityFn::default();
43
44 assert_eq!(into_std_fn_once(Clone::clone(&f))(2), 2);
45 assert_eq!(into_std_fn_mut(Clone::clone(&f))(2), 2);
46 assert_eq!(into_std_fn(Clone::clone(&f))(2), 2);
47 }
48}