about summary refs log tree commit diff
path: root/src/libstd/vec.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-17 00:16:03 -0700
committerbors <bors@rust-lang.org>2013-06-17 00:16:03 -0700
commit90b999aea1a4cfdda549c2ba8462d9eac23c681a (patch)
tree7b9fedf358bc9b25a70d139c01b8fe571a23e11c /src/libstd/vec.rs
parent98bd68343c053ff62cbc6617d04e34c54a3cf720 (diff)
parentf1d971ae189180cbcf3fd37a35ae3fb183833168 (diff)
downloadrust-90b999aea1a4cfdda549c2ba8462d9eac23c681a.tar.gz
rust-90b999aea1a4cfdda549c2ba8462d9eac23c681a.zip
auto merge of #7198 : huonw/rust/slice-zeros, r=Aatch
Diffstat (limited to 'src/libstd/vec.rs')
-rw-r--r--src/libstd/vec.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 3f7bf897be2..e6d7ae0151a 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -2629,6 +2629,12 @@ impl<A:Clone> Clone for ~[A] {
     }
 }
 
+// This works because every lifetime is a sub-lifetime of 'static
+impl<'self, A> Zero for &'self [A] {
+    fn zero() -> &'self [A] { &'self [] }
+    fn is_zero(&self) -> bool { self.is_empty() }
+}
+
 impl<A> Zero for ~[A] {
     fn zero() -> ~[A] { ~[] }
     fn is_zero(&self) -> bool { self.len() == 0 }
@@ -4293,4 +4299,20 @@ mod tests {
         }
         assert_eq!(v, ~[~[1,2,3],~[1,3,2],~[2,1,3],~[2,3,1],~[3,1,2],~[3,2,1]]);
     }
+
+    #[test]
+    fn test_vec_zero() {
+        use num::Zero;
+        macro_rules! t (
+            ($ty:ty) => {
+                let v: $ty = Zero::zero();
+                assert!(v.is_empty());
+                assert!(v.is_zero());
+            }
+        );
+
+        t!(&[int]);
+        t!(@[int]);
+        t!(~[int]);
+    }
 }