This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
fn main() { | |
let action = std::env::args().nth(1).expect("Please provide an action"); | |
let item = std::env::args().nth(2).expect("Please provide an item"); | |
let mut todo = Todo::new().expect("Initialisation of db failed"); | |
if action == "add" { | |
todo.insert(item); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::io::Read; | |
use std::str::FromStr; | |
fn main() { | |
let action = std::env::args().nth(1).expect("Please specify an action"); | |
let item = std::env::args().nth(2).expect("Please specify an item"); | |
let mut todo = Todo::new().expect("Initialisation of db failed"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::io::Read; | |
use std::str::FromStr; | |
fn main() { | |
let action = std::env::args().nth(1).expect("Please specify an action"); | |
let item = std::env::args().nth(2).expect("Please specify an item"); | |
let mut todo = Todo::new().expect("Initialisation of db failed"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
fn main() { | |
let action = std::env::args().nth(1).expect("Please specify an action"); | |
let item = std::env::args().nth(2).expect("Please specify an item"); | |
let mut todo = Todo { | |
map: HashMap::new(), | |
}; | |
if action == "add" { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Exercise: Loops and Functions | |
* As a way to play with functions and loops, implement the square root function using Newton's method. | |
* To begin with, repeat the calculation 10 times and see how close you get to the answer for various values (1, 2, 3, ...). | |
* Next, change the loop condition to stop once the value has stopped changing (or only changes by a very small amount). | |
* See if that's more or fewer than 10 iterations. How close are you to the math.Sqrt? | |
*/ | |
package main |