Initial commit
This commit is contained in:
commit
a4f69cc2c2
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal 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
25
src/file.rs
Normal 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
2
src/lib.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod file;
|
||||||
|
pub mod parse;
|
8
src/parse.rs
Normal file
8
src/parse.rs
Normal 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")));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user