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
fn make_roman_numeral(my_int: i32) -> String { | |
let descending = get_roman_numerals_descending(); | |
let mut roman_numeral = String::new(); | |
let mut remainder = my_int; | |
// find the largest roman numeral smaller than remainder, | |
// append the roman character, and deduct from the remainder, | |
// if roman numeral is not smaller, try the next valid subtractor. | |
// e.g. if remainder is smaller than 10, X, then check if remainder | |
// is smaller than 9, IX, else go down to next numeral, V. |
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
// associate a roman numeral with its value | |
struct RomanNumeral { | |
txt: String, | |
value: i32, | |
} | |
fn is_factor_of_ten(i: i32) -> bool { | |
if i == 1 { | |
return true; | |
} |
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::env; | |
fn main() { | |
// get the command line argument | |
let args: Vec<String> = env::args().collect(); | |
// first command line arg is the program | |
if args.len() < 2 { | |
panic!("must supply a command line argument of the number to convert"); | |
} |
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
#![feature(proc_macro_hygiene, decl_macro)] | |
#[macro_use] extern crate rocket; | |
fn main() { | |
rocket::ignite().mount("/", routes![health_check]).launch(); | |
} | |
#[get("/health")] | |
fn health_check() -> &'static str { |
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 rusoto_core::Region; | |
use rusoto_dynamodb::DynamoDbClient; | |
impl DynamoUserCrud { | |
fn new(local: bool) -> DynamoDbClient { | |
let region = match local { | |
false => Region::UsEast1, | |
true => Region::Custom { | |
name: "us-east-1".to_owned(), | |
endpoint: "http://localhost:4566".to_owned() |
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
// to block and await | |
use futures::executor::block_on; | |
// Would allow us to swap out implementations for testing or to change persistence layer | |
trait UserCrud { | |
fn get_user(&self, id: String) -> Result<User, &'static str>; | |
fn delete_user(&self, id: String) -> Result<bool, &'static str>; | |
fn save_user(&self, user: User) -> Result<bool, &'static str>; | |
} |
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
async fn dynamo_save_user(client: &DynamoDbClient, table_name: String, user: User) -> Result<bool, &'static str> { | |
let input = PutItemInput{ | |
table_name: table_name, | |
item: user.to_map(), | |
..Default::default() | |
}; | |
match client.put_item(input).await { | |
Err(error) => { | |
println!("Error saving dynamo item {:?}", error); | |
Err("error saving dynamo 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
extern crate rusoto_dynamodb; | |
use rusoto_dynamodb::*; | |
async fn dynamo_get_user(client: &DynamoDbClient, table_name: String, id: String) -> Result<User, &'static str> { | |
let mut get_key = HashMap::new(); | |
get_key.insert( | |
"id".to_string(), | |
AttributeValue { | |
s: Some(id.to_string()), | |
..Default::default() |
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
extern crate rusoto_dynamodb; | |
use rusoto_dynamodb::AttributeValue; | |
use std::default::Default; | |
use std::result::Result; | |
impl User { | |
fn from_map(map: HashMap<String, AttributeValue>) -> Result<User, &'static str> { | |
return Ok(User { | |
id: match map.get("id") { |
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
[dependencies] | |
rusoto_core = "0.44.0" | |
rusoto_dynamodb = "0.44.0" |
NewerOlder