Debian Codegraph @

src/std_unstable.rs

raw symbols SCIP
1 /*
2 Copyright ⓒ 2015 rust-custom-derive contributors.
3
4 Licensed under the MIT license (see LICENSE or <http://opensource.org
5 /licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
6 <http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
7 files in the project carrying such notice may not be copied, modified,
8 or distributed except according to those terms.
9 */
10 #![cfg(feature = "std-unstable")]
11
12 #[macro_export]
13 macro_rules! NewtypeOne {
14 (() $(pub)* struct $name:ident(pub $_t0:ty);) => {
15 impl ::std::num::One for $name {
16 fn one() -> Self {
17 $name(::std::num::One::one())
18 }
19 }
20 };
21
22 (() $(pub)* struct $name:ident($_t0:ty);) => {
23 impl ::std::num::One for $name {
24 fn one() -> Self {
25 $name(::std::num::One::one())
26 }
27 }
28 };
29 }
30
31 #[macro_export]
32 macro_rules! NewtypeProduct {
33 ($arg:tt $(pub)* struct $name:ident(pub $t0:ty);) => {
34 NewtypeProduct! { $arg struct $name($t0); }
35 };
36
37 (() $(pub)* struct $name:ident($t0:ty);) => {
38 impl ::std::iter::Product<$name> for $name {
39 fn product<I>(iter: I) -> Self
40 where I: Iterator<Item=$name> {
41 $name(iter.map(|e| e.0).product::<$t0>())
42 }
43 }
44 };
45
46 ((&Self) $(pub)* struct $name:ident($t0:ty);) => {
47 impl<'a> ::std::iter::Product<&'a $name> for $name {
48 fn product<I>(iter: I) -> Self
49 where I: Iterator<Item=&'a $name> {
50 $name(iter.map(|e| &e.0).product::<$t0>())
51 }
52 }
53 };
54 }
55
56 #[macro_export]
57 macro_rules! NewtypeSum {
58 ($arg:tt $(pub)* struct $name:ident(pub $t0:ty);) => {
59 NewtypeSum! { $arg struct $name($t0); }
60 };
61
62 (() $(pub)* struct $name:ident($t0:ty);) => {
63 impl ::std::iter::Sum<$name> for $name {
64 fn sum<I>(iter: I) -> Self
65 where I: Iterator<Item=$name> {
66 $name(iter.map(|e| e.0).sum::<$t0>())
67 }
68 }
69 };
70
71 ((&Self) $(pub)* struct $name:ident($t0:ty);) => {
72 impl<'a> ::std::iter::Sum<&'a $name> for $name {
73 fn sum<I>(iter: I) -> Self
74 where I: Iterator<Item=&'a $name> {
75 $name(iter.map(|e| &e.0).sum::<$t0>())
76 }
77 }
78 };
79 }
80
81 #[macro_export]
82 macro_rules! NewtypeZero {
83 (() $(pub)* struct $name:ident(pub $_t0:ty);) => {
84 impl ::std::num::Zero for $name {
85 fn zero() -> Self {
86 $name(::std::num::Zero::zero())
87 }
88 }
89 };
90
91 (() $(pub)* struct $name:ident($_t0:ty);) => {
92 impl ::std::num::Zero for $name {
93 fn zero() -> Self {
94 $name(::std::num::Zero::zero())
95 }
96 }
97 };
98 }