about summary refs log tree commit diff
path: root/src/libstd/num/num.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-16 01:52:09 -0700
committerbors <bors@rust-lang.org>2013-06-16 01:52:09 -0700
commit08c1155a223eb79960e7a5dbb0ea6276ef9754ea (patch)
treefdbb9cbe16c75d9cb615fc651a3946fb6391ed17 /src/libstd/num/num.rs
parentd1927d295013e19e57a9773c37ded698e89392eb (diff)
parent893c70d7bc670054ef646b71d4d503298cc50d76 (diff)
downloadrust-08c1155a223eb79960e7a5dbb0ea6276ef9754ea.tar.gz
rust-08c1155a223eb79960e7a5dbb0ea6276ef9754ea.zip
auto merge of #7142 : alexcrichton/rust/deriving-zero, r=pcwalton
This allows mass-initialization of large structs without having to specify all the fields.

I'm a bit hesitant, but I wanted to get this out there. I don't really like using the `Zero` trait, because it doesn't really make sense for a type like `HashMap` to use `Zero` as the 'blank allocation' trait. In theory there'd be a new trait, but then that's adding cruft to the language which may not necessarily need to be there.

I do think that this can be useful, but I only implemented `Zero` on the basic types where I thought it made sense, so it may not be all that usable yet. (opinions?)
Diffstat (limited to 'src/libstd/num/num.rs')
-rw-r--r--src/libstd/num/num.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/num/num.rs b/src/libstd/num/num.rs
index a9893579721..4681e4f4f53 100644
--- a/src/libstd/num/num.rs
+++ b/src/libstd/num/num.rs
@@ -418,6 +418,21 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(radix: uint, pow
     total
 }
 
+impl<T: Zero> Zero for @mut T {
+    fn zero() -> @mut T { @mut Zero::zero() }
+    fn is_zero(&self) -> bool { (**self).is_zero() }
+}
+
+impl<T: Zero> Zero for @T {
+    fn zero() -> @T { @Zero::zero() }
+    fn is_zero(&self) -> bool { (**self).is_zero() }
+}
+
+impl<T: Zero> Zero for ~T {
+    fn zero() -> ~T { ~Zero::zero() }
+    fn is_zero(&self) -> bool { (**self).is_zero() }
+}
+
 /// Helper function for testing numeric operations
 #[cfg(test)]
 pub fn test_num<T:Num + NumCast>(ten: T, two: T) {