1 // ***Remember to enable/add this part in `main.rs`!***
3 // Rust-101, Part 06: Copy, Lifetimes
4 // ==================================
6 // We continue to work on our `BigInt`, so we start by importing what we already established.
9 // With `BigInt` being about numbers, we should be able to write a version of `vec_min`
10 // that computes the minimum of a list of `BigInt`. First, we have to write `min` for `BigInt`.
12 fn min_try1(self, other: Self) -> Self {
13 debug_assert!(self.test_invariant() && other.test_invariant());
14 // Now our assumption of having no trailing zeros comes in handy:
15 // If the lengths of the two numbers differ, we already know which is larger.
16 if self.data.len() < other.data.len() {
18 } else if self.data.len() > other.data.len() {
21 // **Exercise 06.1**: Fill in this code.
27 // Now we can write `vec_min`.
28 fn vec_min(v: &Vec<BigInt>) -> Option<BigInt> {
29 let mut min: Option<BigInt> = None;
38 use part02::{SomethingOrNothing,Something,Nothing};
39 impl<T: Copy> Copy for SomethingOrNothing<T> {}
44 fn head<T>(v: &Vec<T>) -> Option<&T> {
51 // Technically, we are returning a pointer to the first element. But doesn't that mean that callers have to be
52 // careful? Imagine `head` would be a C++ function, and we would write the following code.
54 int foo(std::vector<int> v) {
60 fn rust_foo(mut v: Vec<i32>) -> i32 {
61 let first: Option<&i32> = head(&v);