Some more clean up.

This commit is contained in:
Cutieguwu
2024-12-06 17:47:56 -05:00
parent 558b9fc162
commit 1fdf7aa53c
2 changed files with 27 additions and 17 deletions

View File

@@ -51,10 +51,10 @@ pub struct Standing {
}
impl Standing {
pub fn calculate (mut self: Standing) -> i8 {
pub fn calculate (mut self: Self) -> i8 {
// Drain society points if mostly disliked.
if self.friends.len() < self.enemies.len() {
self.society = self.society.clone() - 2
self.society = &self.society - 2
}
// Points

View File

@@ -1,9 +1,8 @@
use std::{
env::args,
io,
io, ops::Deref,
};
const DASH: char = 45 as u8 as char;
#[derive(Debug, Clone)]
@@ -24,26 +23,34 @@ pub enum FlagType {
pub fn fmt_args() -> Vec<ArgType> {
let mut args_vec:Vec<ArgType> = Vec::new();
for obj in args() { match try_flag(obj.clone()) {
None => args_vec.push(ArgType::Command(obj)),
Some(flag) => args_vec.push(ArgType::Flag(flag)),
}}
for obj in args() {
args_vec.push(match try_flag(&obj) {
None => ArgType::Command(obj),
Some(flag) => ArgType::Flag(flag),
})
};
args_vec[0] = ArgType::Binary(match args_vec[0].clone() {
ArgType::Command(command) => command,
err => panic!("Expected ArgType::Command at args_vec[0], found {:?}", err)
args_vec[0] = ArgType::Binary(match &args_vec[0] {
ArgType::Command(command) => command.clone(),
err => panic!(
"Expected ArgType::Command at args_vec[0], found {:?}",
err,
)
});
args_vec
}
fn try_flag(arg: String) -> Option<FlagType> {
if arg.chars().nth(1).unwrap() == DASH {
fn try_flag<'a>(arg: &'a String) -> Option<FlagType> {
// Short term var to reduce number of chars() calls.
let mut arg_chars = arg.chars();
if arg_chars.nth(1).unwrap() == DASH {
//eg. --my-flag
Some(FlagType::Long(break_flag_long(arg)))
} else if arg.chars().nth(0).unwrap() == DASH {
Some(FlagType::Long(break_flag_long(arg.clone())))
} else if arg_chars.nth(0).unwrap() == DASH {
//eg. -Syu
Some(FlagType::Short(break_flag_short(arg)))
Some(FlagType::Short(break_flag_short(arg.clone())))
} else {
None
}
@@ -51,11 +58,14 @@ fn try_flag(arg: String) -> Option<FlagType> {
fn break_flag_short(mut arg: String) -> String {
arg.remove(0);
arg
}
fn break_flag_long(mut arg: String) -> String {
for _ in 1..=2 { arg.remove(0); };
for _ in 1..=2 {
arg.remove(0);
};
arg
}