2022 Rust directory

This commit is contained in:
Maciej Jur 2022-11-27 00:25:48 +01:00
parent bd10a789f5
commit 4832842f24
7 changed files with 63 additions and 0 deletions

7
2022/rust/Cargo.lock generated Normal file
View 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
View 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]

View file

@ -0,0 +1,6 @@
a
b
c
d
sss
asas

7
2022/rust/src/main.rs Normal file
View file

@ -0,0 +1,7 @@
mod utils;
mod solutions;
fn main() {
solutions::day01::run();
}

View 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);
}
}

View file

@ -0,0 +1 @@
pub mod day01;

24
2022/rust/src/utils.rs Normal file
View 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()
}