From 7150eb75b456696ea10e58c7fd12bae8b686e0ad Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Tue, 27 Jun 2023 16:43:48 -0400 Subject: [PATCH] Beginning foundations - data loading --- .gitignore | 3 +++ .vscode/settings.json | 5 +++++ Cargo.toml | 3 ++- src/commands.rs | 0 src/data_loader.rs | 20 ++++++++++++++++++++ src/main.rs | 11 +++++++++-- 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/commands.rs create mode 100644 src/data_loader.rs diff --git a/.gitignore b/.gitignore index 3ca43ae..ca9fda9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +# SECRETS +secrets/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ec17418 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "rust-analyzer.linkedProjects": [ + ".\\Cargo.toml" + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b1bbefc..6481ef4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [package] -name = "Spekkio" +name = "spekkio" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +poise = "0.5.5" diff --git a/src/commands.rs b/src/commands.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/data_loader.rs b/src/data_loader.rs new file mode 100644 index 0000000..6661ebf --- /dev/null +++ b/src/data_loader.rs @@ -0,0 +1,20 @@ + +use std::{io::prelude::*, fs::File, path::Path }; + +pub fn load_token(file_name: &str) -> String +{ + let mut file = match File::open(Path::new(file_name)) + { + Ok(file) => file, + Err(why) => panic!("Could not open token file {}: {}", Path::new(file_name).display(), why), + }; + + let mut s = String::new(); + let token = match file.read_to_string(&mut s) + { + Err(why) => panic!("couldn't read {}: {}", Path::new(file_name).display(), why), + Ok(_) => s, + }; + + token +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7a11a9..a0cbe23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,10 @@ -fn main() { - println!("Hello, world!"); + +mod commands; +mod data_loader; + +fn main() +{ + let token = data_loader::load_token("secrets/test.txt"); + println!("test data: {}", token); + }