2022 Rust directory
This commit is contained in:
parent
bd10a789f5
commit
4832842f24
7
2022/rust/Cargo.lock
generated
Normal file
7
2022/rust/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
8
2022/rust/Cargo.toml
Normal file
8
2022/rust/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
6
2022/rust/inputs/scratch.txt
Normal file
6
2022/rust/inputs/scratch.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
sss
|
||||
asas
|
7
2022/rust/src/main.rs
Normal file
7
2022/rust/src/main.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
mod utils;
|
||||
mod solutions;
|
||||
|
||||
|
||||
fn main() {
|
||||
solutions::day01::run();
|
||||
}
|
10
2022/rust/src/solutions/day01.rs
Normal file
10
2022/rust/src/solutions/day01.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use crate::utils;
|
||||
|
||||
pub fn run() -> () {
|
||||
let data = utils::read_lines(utils::Source::Scratch);
|
||||
|
||||
println!("Day 1");
|
||||
for x in data {
|
||||
println!("{}", x);
|
||||
}
|
||||
}
|
1
2022/rust/src/solutions/mod.rs
Normal file
1
2022/rust/src/solutions/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod day01;
|
24
2022/rust/src/utils.rs
Normal file
24
2022/rust/src/utils.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::Path;
|
||||
|
||||
|
||||
pub enum Source { Scratch, Day(i32) }
|
||||
|
||||
|
||||
pub fn read_lines(source: Source) -> Vec<String> {
|
||||
let path = match source {
|
||||
Source::Scratch => "inputs/scratch.txt".to_string(),
|
||||
Source::Day(day) => {
|
||||
assert!(1 <= day && day < 25);
|
||||
format!("inputs/day{:0>2}.txt", day)
|
||||
}
|
||||
};
|
||||
_read_lines(&path).expect(format!("Failed to load from {}", &path).as_str())
|
||||
}
|
||||
|
||||
fn _read_lines<P>(filename: P) -> std::io::Result<Vec<String>>
|
||||
where P: AsRef<Path> {
|
||||
let file = File::open(filename)?;
|
||||
BufReader::new(file).lines().collect()
|
||||
}
|
Loading…
Reference in a new issue