rust_rewrite #11
@ -8,3 +8,5 @@ authors = ["thomas"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.39", features = ["derive"] }
|
clap = { version = "4.5.39", features = ["derive"] }
|
||||||
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
|
serde_json = "1.0.140"
|
||||||
|
15
src/config.rs
Normal file
15
src/config.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
use crate::types;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Body {
|
||||||
|
name: String,
|
||||||
|
mass: types::Mass,
|
||||||
|
position: types::Position,
|
||||||
|
velocity: types::Velocity,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct ConfigFile {
|
||||||
|
bodies: Vec<Body>,
|
||||||
|
}
|
21
src/main.rs
21
src/main.rs
@ -1,5 +1,13 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
|
||||||
|
mod types;
|
||||||
|
mod config;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(
|
#[command(
|
||||||
@ -18,8 +26,21 @@ struct Args {
|
|||||||
step_size: u8,
|
step_size: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_config<P: AsRef<Path>>(path: P) -> Result<config::ConfigFile, Box<dyn Error>> {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
let u = serde_json::from_reader(reader)?;
|
||||||
|
|
||||||
|
Ok(u)
|
||||||
|
}
|
||||||
|
//fn parse_time(arg: &str)
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
println!("Loading initial parameters from {}", args.config);
|
println!("Loading initial parameters from {}", args.config);
|
||||||
|
|
||||||
|
let conf = read_config(args.config).unwrap();
|
||||||
|
println!("{:#?}", conf);
|
||||||
}
|
}
|
||||||
|
5
src/types.rs
Normal file
5
src/types.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub type Hval = f64;
|
||||||
|
pub type Position = [Hval; 3];
|
||||||
|
pub type Velocity = [Hval; 3];
|
||||||
|
pub type Acceleration = [Hval; 3];
|
||||||
|
pub type Mass = Hval;
|
Loading…
x
Reference in New Issue
Block a user