Browse Source

WIP project structure

develop-refactor
chodak166 6 months ago
parent
commit
93ea6c305d
  1. 11
      Cargo.toml
  2. 12
      app/Cargo.toml
  3. 81
      app/src/main.rs
  4. 6
      lib/Cargo.toml
  5. 0
      lib/src/core/major_system_encoder.rs
  6. 0
      lib/src/core/traits/system_encoder.rs
  7. 28
      lib/src/lib.rs

11
Cargo.toml

@ -0,0 +1,11 @@
[workspace]
members = [
"app",
"lib",
]
resolver = "3"
[workspace.package]
edition = "2024"
authors = ["chodak166 <chodak166@op.pl>"]
license = "MIT"

12
app/Cargo.toml

@ -0,0 +1,12 @@
[package]
name = "mnemo-r"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = { version = "4.5.51", features = ["derive"] }
libmnemor = { path = "../lib" }
[profile.release]
lto = true # Link Time Optimization: Analyzes entire program for optimizations
codegen-units = 1 # Forces single-threaded compilation (slower build, but smaller/faster binary)

81
app/src/main.rs

@ -0,0 +1,81 @@
use clap::{Parser, ValueEnum};
#[derive(ValueEnum, Debug, Clone)]
enum System {
#[value(name = "major-en")]
MajorEn,
#[value(name = "major-pl")]
MajorPl,
}
trait SystemEncoder {
fn encode(&self, word: &str) -> String;
}
struct MajorEncoder {
dict: String, // TODO
}
impl SystemEncoder for MajorEncoder {
fn encode(&self, word: &str) -> String {
let num_word: String = word
.chars()
.map(|c| c.to_digit(10).unwrap_or(0).to_string())
.collect();
format!("{}_{} -> {}", word, self.dict, num_word)
}
}
fn create_encoder(system: &System) -> Box<dyn SystemEncoder> {
match system {
System::MajorPl => Box::new(MajorEncoder {
dict: String::from("dict-major-pl"),
}),
System::MajorEn => Box::new(MajorEncoder {
dict: String::from("dict-major-en"),
}),
}
}
#[derive(Parser)]
#[command(author, version, about)]
struct CliArgs {
/// System name
#[arg(short, long, default_value = "major-pl")]
system: System,
/// Encode given word
#[arg(short, long)]
encode: Option<String>,
/// List supported systems
#[arg(long)]
list_systems: bool,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = CliArgs::parse();
if args.list_systems {
println!("Supported systems:");
for system in System::value_variants() {
if let Some(possible_value) = system.to_possible_value() {
println!("- {}", possible_value.get_name());
}
}
return Ok(());
}
if let Some(word) = args.encode {
println!(
"Encoding {} with system {:?}...",
word,
args.system.to_possible_value().unwrap().get_name()
);
let encoder = create_encoder(&args.system);
let encoded_word = encoder.encode(&word);
println!("Encoded: [{}]", encoded_word);
}
Ok(())
}

6
lib/Cargo.toml

@ -0,0 +1,6 @@
[package]
name = "libmnemor"
version = "0.1.0"
edition = "2024"
[dependencies]

0
lib/src/core/major_system_encoder.rs

0
lib/src/core/traits/system_encoder.rs

28
lib/src/lib.rs

@ -0,0 +1,28 @@
pub struct TextProcessor {
prefix: String,
}
impl TextProcessor {
/// Create a new processor with custom prefix
pub fn new(prefix: &str) -> Self {
Self {
prefix: prefix.to_string(),
}
}
/// Process input text by adding prefix and converting to uppercase
pub fn process(&self, input: &str) -> String {
format!("{} {}", self.prefix, input.to_uppercase())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_processing() {
let processor = TextProcessor::new(">> ");
assert_eq!(processor.process("hello"), ">> HELLO");
}
}
Loading…
Cancel
Save