Some more clean up.
This commit is contained in:
@@ -51,10 +51,10 @@ pub struct Standing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Standing {
|
impl Standing {
|
||||||
pub fn calculate (mut self: Standing) -> i8 {
|
pub fn calculate (mut self: Self) -> i8 {
|
||||||
// Drain society points if mostly disliked.
|
// Drain society points if mostly disliked.
|
||||||
if self.friends.len() < self.enemies.len() {
|
if self.friends.len() < self.enemies.len() {
|
||||||
self.society = self.society.clone() - 2
|
self.society = &self.society - 2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Points
|
// Points
|
||||||
|
|||||||
40
src/utils.rs
40
src/utils.rs
@@ -1,9 +1,8 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
io,
|
io, ops::Deref,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const DASH: char = 45 as u8 as char;
|
const DASH: char = 45 as u8 as char;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -24,26 +23,34 @@ pub enum FlagType {
|
|||||||
pub fn fmt_args() -> Vec<ArgType> {
|
pub fn fmt_args() -> Vec<ArgType> {
|
||||||
let mut args_vec:Vec<ArgType> = Vec::new();
|
let mut args_vec:Vec<ArgType> = Vec::new();
|
||||||
|
|
||||||
for obj in args() { match try_flag(obj.clone()) {
|
for obj in args() {
|
||||||
None => args_vec.push(ArgType::Command(obj)),
|
args_vec.push(match try_flag(&obj) {
|
||||||
Some(flag) => args_vec.push(ArgType::Flag(flag)),
|
None => ArgType::Command(obj),
|
||||||
}}
|
Some(flag) => ArgType::Flag(flag),
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
args_vec[0] = ArgType::Binary(match args_vec[0].clone() {
|
args_vec[0] = ArgType::Binary(match &args_vec[0] {
|
||||||
ArgType::Command(command) => command,
|
ArgType::Command(command) => command.clone(),
|
||||||
err => panic!("Expected ArgType::Command at args_vec[0], found {:?}", err)
|
err => panic!(
|
||||||
|
"Expected ArgType::Command at args_vec[0], found {:?}",
|
||||||
|
err,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
args_vec
|
args_vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_flag(arg: String) -> Option<FlagType> {
|
fn try_flag<'a>(arg: &'a String) -> Option<FlagType> {
|
||||||
if arg.chars().nth(1).unwrap() == DASH {
|
// 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
|
//eg. --my-flag
|
||||||
Some(FlagType::Long(break_flag_long(arg)))
|
Some(FlagType::Long(break_flag_long(arg.clone())))
|
||||||
} else if arg.chars().nth(0).unwrap() == DASH {
|
} else if arg_chars.nth(0).unwrap() == DASH {
|
||||||
//eg. -Syu
|
//eg. -Syu
|
||||||
Some(FlagType::Short(break_flag_short(arg)))
|
Some(FlagType::Short(break_flag_short(arg.clone())))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -51,11 +58,14 @@ fn try_flag(arg: String) -> Option<FlagType> {
|
|||||||
|
|
||||||
fn break_flag_short(mut arg: String) -> String {
|
fn break_flag_short(mut arg: String) -> String {
|
||||||
arg.remove(0);
|
arg.remove(0);
|
||||||
|
|
||||||
arg
|
arg
|
||||||
}
|
}
|
||||||
|
|
||||||
fn break_flag_long(mut arg: String) -> String {
|
fn break_flag_long(mut arg: String) -> String {
|
||||||
for _ in 1..=2 { arg.remove(0); };
|
for _ in 1..=2 {
|
||||||
|
arg.remove(0);
|
||||||
|
};
|
||||||
|
|
||||||
arg
|
arg
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user