Skip to content

Commit

Permalink
Merge pull request #1842 from MrAwesome/psp_copy_clone_macros
Browse files Browse the repository at this point in the history
Create macros for defining Copy/Clone on enums and struct(), use for psp
  • Loading branch information
JohnTitor authored Jul 27, 2020
2 parents f1fdb96 + 2d5fc45 commit fb6a306
Show file tree
Hide file tree
Showing 2 changed files with 1,238 additions and 1,414 deletions.
30 changes: 30 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,36 @@ macro_rules! s_no_extra_traits {
);
}

#[allow(unused_macros)]
macro_rules! e {
($($(#[$attr:meta])* pub enum $i:ident { $($field:tt)* })*) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
$(#[$attr])*
pub enum $i { $($field)* }
}
impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
)*);
}

#[allow(unused_macros)]
macro_rules! s_paren {
($($(#[$attr:meta])* pub struct $i:ident ( $($field:tt)* ); )* ) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
$(#[$attr])*
pub struct $i ( $($field)* );
}
impl ::Copy for $i {}
impl ::Clone for $i {
fn clone(&self) -> $i { *self }
}
)*);
}

// This is a pretty horrible hack to allow us to conditionally mark
// some functions as 'const', without requiring users of this macro
// to care about the "const-extern-fn" feature.
Expand Down
Loading

0 comments on commit fb6a306

Please sign in to comment.