Initial commit

This commit is contained in:
Patrick MARIE 2021-01-17 17:20:54 +01:00
commit a4f69cc2c2
5 changed files with 46 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
Cargo.lock

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "mkz_aoc"
version = "0.1.0"
authors = ["Patrick MARIE <pm@mkz.me>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

25
src/file.rs Normal file
View File

@ -0,0 +1,25 @@
use std::fs;
pub fn read_to_lines(_filename: &str) -> Result<Vec<String>, String> {
let _contents = fs::read_to_string(_filename);
if let Err(v) = _contents {
return Err(format!("Could not read file: {}", v));
}
let lines = _contents.unwrap().lines().map(|x| x.to_string()).collect::<Vec<String>>();
Ok(lines)
}
pub fn read_to_string(_filename: &str) -> Result<String, String> {
let _lines = read_to_lines(_filename);
match _lines {
Ok(lines) => if lines.len() >= 1 {
Ok(lines[0].clone())
} else {
Err(String::from("Missing content"))
},
Err(v) => Err(v)
}
}

2
src/lib.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod file;
pub mod parse;

8
src/parse.rs Normal file
View File

@ -0,0 +1,8 @@
pub fn string_to_usize_vec(input: String) -> Vec<usize> {
input.chars().map(|x| x.to_digit(10).unwrap() as usize).collect()
}
#[test]
fn test_string_to_usize_vec() {
assert_eq!(vec![1, 2, 3, 4], string_to_usize_vec(String::from("1234")));
}