Skip to content

Commit fb6a306

Browse files
authored
Merge pull request #1842 from MrAwesome/psp_copy_clone_macros
Create macros for defining Copy/Clone on enums and struct(), use for psp
2 parents f1fdb96 + 2d5fc45 commit fb6a306

File tree

2 files changed

+1238
-1414
lines changed

2 files changed

+1238
-1414
lines changed

src/macros.rs

+30
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,36 @@ macro_rules! s_no_extra_traits {
121121
);
122122
}
123123

124+
#[allow(unused_macros)]
125+
macro_rules! e {
126+
($($(#[$attr:meta])* pub enum $i:ident { $($field:tt)* })*) => ($(
127+
__item! {
128+
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
129+
$(#[$attr])*
130+
pub enum $i { $($field)* }
131+
}
132+
impl ::Copy for $i {}
133+
impl ::Clone for $i {
134+
fn clone(&self) -> $i { *self }
135+
}
136+
)*);
137+
}
138+
139+
#[allow(unused_macros)]
140+
macro_rules! s_paren {
141+
($($(#[$attr:meta])* pub struct $i:ident ( $($field:tt)* ); )* ) => ($(
142+
__item! {
143+
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
144+
$(#[$attr])*
145+
pub struct $i ( $($field)* );
146+
}
147+
impl ::Copy for $i {}
148+
impl ::Clone for $i {
149+
fn clone(&self) -> $i { *self }
150+
}
151+
)*);
152+
}
153+
124154
// This is a pretty horrible hack to allow us to conditionally mark
125155
// some functions as 'const', without requiring users of this macro
126156
// to care about the "const-extern-fn" feature.

0 commit comments

Comments
 (0)