From c603f08c1b0e2901ef5d9c28338a471a5135c370 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Thu, 7 Dec 2023 16:15:15 -0500 Subject: [PATCH] Day 5 setup --- day_5/.gitignore | 1 + day_5/Cargo.toml | 8 ++++++++ day_5/build.rs | 31 +++++++++++++++++++++++++++++++ day_5/src/main.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 day_5/.gitignore create mode 100644 day_5/Cargo.toml create mode 100644 day_5/build.rs create mode 100644 day_5/src/main.rs diff --git a/day_5/.gitignore b/day_5/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/day_5/.gitignore @@ -0,0 +1 @@ +/target diff --git a/day_5/Cargo.toml b/day_5/Cargo.toml new file mode 100644 index 0000000..44afc53 --- /dev/null +++ b/day_5/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day_5" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day_5/build.rs b/day_5/build.rs new file mode 100644 index 0000000..88d5909 --- /dev/null +++ b/day_5/build.rs @@ -0,0 +1,31 @@ + +use std::{env, fs, path::Path}; + +fn main() +{ + // let out_dir = env::var("OUT_DIR").unwrap(); + // let cwd = env::var("CARGO_MANIFEST_DIR").unwrap(); + // println!("CWD: {}\n", cwd); + // let data_dir = cwd + "\\data"; + // let data_path = Path::new(&data_dir); + // println!("Data path: {}", data_path.to_string_lossy()); + + // let data_path = Path::new("data/test_input"); + + let out_path = format!("target/{}", &env::var("PROFILE").unwrap()); + let out_path = Path::new(&out_path); + //let out_path = Path::new(&out_dir).join(&env::var("PROFILE").unwrap()); + let out_path_data = out_path.join(Path::new("data")); + + if !out_path_data.exists() + { + fs::create_dir(&out_path_data).expect(&format!("Could not create data directory at: {}", out_path_data.to_string_lossy())); + } + + for file in fs::read_dir("data").unwrap() + { + let file = file.unwrap(); + let dest = out_path.join(file.path()); + fs::copy(file.path(), &dest).expect(&format!("Could not copy file {} to {}", file.path().to_string_lossy(), dest.to_string_lossy())); + } +} \ No newline at end of file diff --git a/day_5/src/main.rs b/day_5/src/main.rs new file mode 100644 index 0000000..3416e1e --- /dev/null +++ b/day_5/src/main.rs @@ -0,0 +1,26 @@ + +use std::{io::prelude::*, fs::File, path::Path, io }; + +fn main() +{ + +} + + +fn load_data(file_name: &str) -> String +{ + let mut file = match File::open(Path::new(file_name)) + { + Ok(file) => file, + Err(why) => panic!("Could not open file {}: {}", Path::new(file_name).display(), why), + }; + + let mut s = String::new(); + let file_contents = match file.read_to_string(&mut s) + { + Err(why) => panic!("couldn't read {}: {}", Path::new(file_name).display(), why), + Ok(_) => s, + }; + + return file_contents; +} \ No newline at end of file