mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
core: implement Clone for primitive types
This commit is contained in:
parent
a5fae1dac7
commit
bef5396af6
2 changed files with 47 additions and 3 deletions
|
@ -19,3 +19,31 @@ impl Clone for () {
|
|||
#[inline(always)]
|
||||
fn clone(&self) -> () { () }
|
||||
}
|
||||
|
||||
macro_rules! clone_impl(
|
||||
($t:ty) => {
|
||||
impl Clone for $t {
|
||||
#[inline(always)]
|
||||
fn clone(&self) -> $t { *self }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
clone_impl!(int)
|
||||
clone_impl!(i8)
|
||||
clone_impl!(i16)
|
||||
clone_impl!(i32)
|
||||
clone_impl!(i64)
|
||||
|
||||
clone_impl!(uint)
|
||||
clone_impl!(u8)
|
||||
clone_impl!(u16)
|
||||
clone_impl!(u32)
|
||||
clone_impl!(u64)
|
||||
|
||||
clone_impl!(float)
|
||||
clone_impl!(f32)
|
||||
clone_impl!(f64)
|
||||
|
||||
clone_impl!(bool)
|
||||
clone_impl!(char)
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
#[deriving_clone]
|
||||
struct S {
|
||||
foo: (),
|
||||
bar: ()
|
||||
_int: int,
|
||||
_i8: i8,
|
||||
_i16: i16,
|
||||
_i32: i32,
|
||||
_i64: i64,
|
||||
|
||||
_uint: uint,
|
||||
_u8: u8,
|
||||
_u16: u16,
|
||||
_u32: u32,
|
||||
_u64: u64,
|
||||
|
||||
_float: float,
|
||||
_f32: f32,
|
||||
_f64: f64,
|
||||
|
||||
_bool: bool,
|
||||
_char: char,
|
||||
_nil: ()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue