about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-04-30 20:46:51 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-07 08:13:56 -0700
commitdfd967f239a079cf90f45bfc3d827547e6fe9008 (patch)
tree8967850d349d0835c2c3225a42cce65d1f958f16 /src/libcore
parent17cb238ee80726c057a16c90b8c4e7e8bfd25c9d (diff)
downloadrust-dfd967f239a079cf90f45bfc3d827547e6fe9008.tar.gz
rust-dfd967f239a079cf90f45bfc3d827547e6fe9008.zip
core: Inherit the default module
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/default.rs27
-rw-r--r--src/libcore/lib.rs1
2 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/default.rs b/src/libcore/default.rs
new file mode 100644
index 00000000000..9cf3a763648
--- /dev/null
+++ b/src/libcore/default.rs
@@ -0,0 +1,27 @@
+// 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.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! The `Default` trait for types which may have meaningful default values
+
+use owned::Box;
+
+/// A trait that types which have a useful default value should implement.
+pub trait Default {
+    /// Return the "default value" for a type.
+    fn default() -> Self;
+}
+
+impl<T: Default + 'static> Default for @T {
+    fn default() -> @T { @Default::default() }
+}
+
+impl<T: Default> Default for Box<T> {
+    fn default() -> Box<T> { box Default::default() }
+}
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index fe4809a5001..6730c252f52 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -33,6 +33,7 @@ pub mod ptr;
 pub mod kinds;
 pub mod ops;
 pub mod ty;
+pub mod default;
 pub mod container;
 
 /* Core types and methods on primitives */