From cf3e278f76a00576f5a84ae3bab1a9a73db46123 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 20 Jan 2013 20:10:25 -0500 Subject: [PATCH] add default Clone impl for all copyable types --- src/libcore/clone.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 6fbcf2df45406..0de8b04e0acfe 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,14 +8,34 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/** -Clonable types are copied with the clone method -*/ +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + +use prelude::Copy; + +/// Clonable types are copied with the clone method pub trait Clone { fn clone(&self) -> self; } -impl (): Clone { +impl T: Clone { #[inline(always)] - fn clone(&self) -> () { () } + fn clone(&self) -> T { copy *self } +} + +#[cfg(test)] +mod test { + #[test] + fn test_int() { + let x = 5; + let y = x.clone(); + assert x == y; + } + + #[test] + fn test_str() { + let x = ~"foo"; + let y = x.clone(); + assert x == y; + } }