Set up repo for Rust problems

This commit is contained in:
Fizzizist
2025-02-22 16:29:08 -05:00
parent 389773d411
commit 287d599e82
8 changed files with 310 additions and 50 deletions

32
rust/src/main.rs Normal file
View File

@@ -0,0 +1,32 @@
mod solutions;
mod utils;
use clap::Parser;
use utils::run_solution;
#[derive(clap::ValueEnum, Clone, Debug)]
enum Problem {
REVP,
}
#[derive(Parser, Debug)]
#[command(
name = "Rosalind Problems",
version = "v0.0.0",
author = "Peter Vlasveld <peter@vlasveld.info>",
about = "Solves Problems from rosalind.info"
)]
struct Args {
#[arg(short, long)]
problem: Problem,
#[arg(short, long)]
input_file: String,
#[arg(short, long, default_value = "output.txt")]
output_file: String,
}
fn main() {
let args = Args::parse();
run_solution(args.problem, &args.input_file, &args.output_file);
}

View File

@@ -0,0 +1,2 @@
mod revp;
pub use revp::revp;

View File

@@ -0,0 +1,3 @@
pub fn revp(file_content: String) -> String {
"placeholder".to_string()
}

20
rust/src/utils.rs Normal file
View File

@@ -0,0 +1,20 @@
use crate::{solutions, Problem};
use std::{fs, io};
pub fn run_solution(problem: Problem, in_file: &String, out_file: &String) {
// parse the input file into a string
let solution: io::Result<String> = match fs::read_to_string(in_file) {
Ok(content) => match problem {
Problem::REVP => Ok(solutions::revp(content)),
},
Err(e) => Err(e),
};
match solution {
Ok(out_content) => match fs::write(out_file, &out_content) {
Ok(_) => println!("{:?}", out_content),
Err(e) => println!("Error writing to output file: {e}"),
},
Err(e) => println!("An error occured reading the input file: {e}"),
};
}