diff --git a/Cargo.lock b/Cargo.lock index c5bccfb..2816608 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,12 +38,27 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +dependencies = [ + "serde", +] + [[package]] name = "bytes" version = "1.5.0" @@ -69,6 +84,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "chorus" version = "0.1.0" dependencies = [ + "ron", "serde", "thiserror", "tokio", @@ -200,7 +216,19 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", +] + +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64", + "bitflags 2.4.1", + "serde", + "serde_derive", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0470b8b..64afea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/mikedilger/chorus" edition = "2021" [dependencies] +ron = "0.8" serde = { version = "1.0", features = ["derive"] } thiserror = "1.0" tokio = { version = "1", features = [ "full" ] } diff --git a/sample/sample.config.ron b/sample/sample.config.ron new file mode 100644 index 0000000..9348a43 --- /dev/null +++ b/sample/sample.config.ron @@ -0,0 +1,4 @@ +Config( + ip_address: "127.0.0.1", + port: 8080, +) \ No newline at end of file diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..97548bb --- /dev/null +++ b/src/config.rs @@ -0,0 +1,16 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + pub ip_address: String, + pub port: u16, +} + +impl Default for Config { + fn default() -> Config { + Config { + ip_address: "127.0.0.1".to_string(), + port: 80, + } + } +} diff --git a/src/error.rs b/src/error.rs index 089bd99..ff9e8c8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,10 @@ use thiserror::Error; /// Errors that can occur in the chorus crate #[derive(Error, Debug)] pub enum Error { + // Config + #[error("Config: {0}")] + Config(#[from] ron::error::SpannedError), + // I/O Error #[error("I/O: {0}")] Io(#[from] std::io::Error), diff --git a/src/main.rs b/src/main.rs index 018d739..072ead2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,29 @@ + +pub mod config; pub mod error; +use crate::config::Config; use crate::error::Error; +use std::env; +use std::fs::OpenOptions; +use std::io::Read; #[tokio::main] async fn main() -> Result<(), Error> { + // Get args (config path) + let mut args = env::args(); + if args.len() <= 1 { + panic!("USAGE: chorus "); + } + let _ = args.next(); // ignore program name + let config_path = args.next().unwrap(); + + // Read config file + let mut file = OpenOptions::new().read(true).open(config_path)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + let config: Config = ron::from_str(&contents)?; + println!("No main yet."); Ok(())