+ // We know that the result will be *at least* as long as the longer of the two operands,
+ // so we can create a vector with sufficient capacity to avoid expensive reallocations.
+ let max_len = cmp::max(self.data.len(), rhs.data.len());
+ let mut result_vec:Vec<u64> = Vec::with_capacity(max_len);
+ let mut carry = false; /* the current carry bit */
+ for i in 0..max_len {
+ // Compute next digit and carry. Store the digit for the result, and the carry for later.
+ let lhs_val = if i < self.data.len() { self.data[i] } else { 0 };
+ let rhs_val = if i < rhs.data.len() { rhs.data[i] } else { 0 };
+ unimplemented!()
+ }
+ // **Exercise 08.2**: Handle the final `carry`, and return the sum.
+ unimplemented!()
+ }
+}
+
+// ## Traits and borrowed types
+
+// Writing this out becomes a bit tedious, because trait implementations (unlike functions) require full explicit annotation
+// of lifetimes. Make sure you understand exactly what the following definition says.
+impl<'a, 'b> ops::Add<&'a BigInt> for &'b BigInt {
+ type Output = BigInt;
+ fn add(self, rhs: &'a BigInt) -> Self::Output {
+ // **Exercise 08.3**: Implement this function.