]> git.lizzy.rs Git - rust.git/commitdiff
Implements Default trait for BigInt and BigUint
authorPiotr Jawniak <sawyer47@gmail.com>
Tue, 13 May 2014 09:00:11 +0000 (11:00 +0200)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 14 May 2014 00:24:07 +0000 (17:24 -0700)
src/libnum/bigint.rs

index ef6f1aafe8864f9a74da4291f04f80265505298d..ac8da664de751ee71e379c37e2c292a06979ceb4 100644 (file)
@@ -19,6 +19,7 @@
 use Integer;
 
 use std::cmp;
+use std::default::Default;
 use std::fmt;
 use std::from_str::FromStr;
 use std::num::CheckedDiv;
@@ -112,6 +113,11 @@ fn cmp(&self, other: &BigUint) -> Ordering {
     }
 }
 
+impl Default for BigUint {
+    #[inline]
+    fn default() -> BigUint { BigUint::new(Vec::new()) }
+}
+
 impl fmt::Show for BigUint {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f.buf, "{}", self.to_str_radix(10))
@@ -830,6 +836,11 @@ fn cmp(&self, other: &BigInt) -> Ordering {
     }
 }
 
+impl Default for BigInt {
+    #[inline]
+    fn default() -> BigInt { BigInt::new(Zero, Vec::new()) }
+}
+
 impl fmt::Show for BigInt {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f.buf, "{}", self.to_str_radix(10))