Skip to content

Commit

Permalink
Refactoring (#45)
Browse files Browse the repository at this point in the history
* Fixed clippy

* Fixed clippy...

* bumped Fluent templates

* Updated named to handle Fluent returning Option

* fmt
  • Loading branch information
folkengine authored Jun 11, 2023
1 parent 8aa091c commit 3ffbf54
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cardpack"
description = "Generic Deck of Cards"
version = "0.4.17"
version = "0.4.18"
authors = ["electronicpanopticon <[email protected]>"]
repository = "https://github.com/ImperialBower/cardpack.rs.git"
homepage = "https://github.com/ImperialBower/cardpack.rs"
Expand All @@ -18,11 +18,12 @@ path = "src/lib.rs"

[dependencies]
colored = "2"
fluent-templates = "0.7.1"
fluent-templates = "0.8.0"
lazy_static = "1.4.0"
log = "0.4"
rand = "0.8.5"
term-table = "1.3.2"
unic-langid = { version = "0.9.0", features = ["macros"] }

[dev-dependencies]
rstest = "0.16.0"
rstest = "0.17.0"
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
msrv = "1.56.0"
msrv = "1.63"

cognitive-complexity-threshold = 30

16 changes: 8 additions & 8 deletions src/cards/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Card {
pub fn symbol(&self, lid: &LanguageIdentifier) -> String {
let rank = self.rank.index(lid);
let suit = self.suit.symbol();
format!("{}{}", rank, suit)
format!("{rank}{suit}")
}

/// Returns a Symbol String for the Card in the traditional colors for the Suits.
Expand All @@ -82,10 +82,10 @@ impl Card {
let rank = self.rank.index(lid);
let suit = self.suit.symbol();
match self.suit.name() {
"hearts" | "herz" | "diamonds" => format!("{}{}", rank, suit).red().to_string(),
"laub" => format!("{}{}", rank, suit).green().to_string(),
"schellen" => format!("{}{}", rank, suit).yellow().to_string(),
_ => format!("{}{}", rank, suit),
"hearts" | "herz" | "diamonds" => format!("{rank}{suit}").red().to_string(),
"laub" => format!("{rank}{suit}").green().to_string(),
"schellen" => format!("{rank}{suit}").yellow().to_string(),
_ => format!("{rank}{suit}"),
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ impl Card {
fn determine_index(suit: &Suit, rank: &Rank) -> String {
let rank = rank.index_default();
let suit = suit.index_default();
format!("{}{}", rank, suit)
format!("{rank}{suit}")
}

/// Prioritizes sorting by Suit and then by Rank.
Expand Down Expand Up @@ -149,13 +149,13 @@ impl Named for Card {
fn index(&self, lid: &LanguageIdentifier) -> String {
let rank = self.rank.name.index(lid);
let suit = self.suit.name.index(lid);
format!("{}{}", rank, suit)
format!("{rank}{suit}")
}

fn long(&self, lid: &LanguageIdentifier) -> String {
let rank = self.rank.name.long(lid);
let suit = self.suit.name.long(lid);
format!("{} {}", rank, suit)
format!("{rank} {suit}")
}

fn default_weight(&self) -> u32 {
Expand Down
8 changes: 4 additions & 4 deletions src/cards/decks/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl BridgeBoard {
let west = BridgeBoard::hand_to_pbn_deal_segment(&self.west);
let north = BridgeBoard::hand_to_pbn_deal_segment(&self.north);
let east = BridgeBoard::hand_to_pbn_deal_segment(&self.east);
format!("S:{} {} {} {}", south, west, north, east)
format!("S:{south} {west} {north} {east}")
}

fn hand_to_pbn_deal_segment(hand: &Pile) -> String {
Expand All @@ -201,7 +201,7 @@ impl BridgeBoard {
let diamonds = BridgeBoard::get_suit_string(&Suit::new(DIAMONDS), &mappie);
let clubs = BridgeBoard::get_suit_string(&Suit::new(CLUBS), &mappie);

format!("{}.{}.{}.{}", spades, hearts, diamonds, clubs)
format!("{spades}.{hearts}.{diamonds}.{clubs}")
}

fn get_suit_string(suit: &Suit, mappie: &HashMap<Suit, Pile>) -> String {
Expand Down Expand Up @@ -245,7 +245,7 @@ impl BridgeBoard {
let mut v: Vec<String> = Vec::new();

for c in s.chars() {
v.push(format!("{}{}", c, suit));
v.push(format!("{c}{suit}"));
}
v
}
Expand Down Expand Up @@ -273,7 +273,7 @@ impl Default for BridgeBoard {
impl fmt::Display for BridgeBoard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let sig = self.to_pbn_deal();
write!(f, "{}", sig)
write!(f, "{sig}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cards/decks/standard52.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl Default for Standard52 {
impl fmt::Display for Standard52 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let sig = self.to_index();
write!(f, "{}", sig)
write!(f, "{sig}")
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/cards/pile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ impl Pile {
let suitname = card.suit.name.long(&US_ENGLISH);
let rangname = card.rank.name.long(&GERMAN);
let rankname = card.rank.name.long(&US_ENGLISH);
println!(" {} of {} ", rankname, suitname);
println!(" {} von {} ", rangname, anzugname);
println!(" {rankname} of {suitname} ");
println!(" {rangname} von {anzugname} ");
}
self.demo_short();
}
Expand All @@ -168,20 +168,20 @@ impl Pile {

for lang in languages {
println!();
print!(" Short Symbols in {:<5}: ", format!("{}", lang));
print!(" Short Symbols in {:<5}: ", format!("{lang}"));
print!("{}", self.to_symbol_index_locale(lang));
}

for lang in languages {
println!();
print!(" Short Letters in {:<5}: ", format!("{}", lang));
print!(" Short Letters in {:<5}: ", format!("{lang}"));
print!("{}", self.to_index_locale(lang));
}

println!();
print!(" Shuffle Deck: ");
let shuffled = self.shuffle();
print!("{}", shuffled);
print!("{shuffled}");

println!();
print!(" Sort Deck: ");
Expand Down Expand Up @@ -641,7 +641,7 @@ impl Pile {
pub fn sig_generate_from_strings(strings: &[String]) -> String {
strings
.iter()
.map(|s| format!("{} ", s))
.map(|s| format!("{s} "))
.collect::<String>()
.trim_end()
.to_string()
Expand All @@ -658,7 +658,7 @@ impl Default for Pile {
impl fmt::Display for Pile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let sig = self.to_index();
write!(f, "{}", sig)
write!(f, "{sig}")
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/fluent/named.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fluent_templates::{static_loader, Loader};
use log::error;
use unic_langid::{langid, LanguageIdentifier};

static_loader! {
Expand Down Expand Up @@ -26,7 +27,13 @@ pub trait Named {
/// methods are all just methods simplifying the call to this method.
fn fluent_value(&self, key_section: &str, lid: &LanguageIdentifier) -> std::string::String {
let id = format!("{}-{}", self.name(), key_section);
LOCALES.lookup(lid, id.as_str())
match LOCALES.lookup(lid, id.as_str()) {
None => {
error!("Invalid Fluent Template text_id: {}", lid);
String::from("_")
}
Some(s) => s,
}
}

/// Returns the value of the names' index in the fluent templates.
Expand Down

0 comments on commit 3ffbf54

Please sign in to comment.