Skip to content

Commit

Permalink
Use inferred static array of love versions
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Jan 1, 2024
1 parent eaad7f1 commit e34fc0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
clippy::expect_used
)]
mod types;
use crate::types::{Bitness, BuildSettings, BuildStatistics, LoveVersion, Platform, Project, Target};
use crate::types::{Bitness, BuildSettings, BuildStatistics, LoveVersion, Platform, Project, Target, LOVE_VERSIONS};

mod build;
mod download;
Expand Down Expand Up @@ -51,7 +51,7 @@ enum BoonOpt {
long,
short,
help = "Specify which target version of LÖVE to build for",
possible_values=&LoveVersion::variants(),
possible_values=LOVE_VERSIONS,
default_value="11.5",
)]
version: LoveVersion,
Expand All @@ -69,12 +69,12 @@ enum BoonOpt {
enum LoveSubcommand {
#[structopt(about = "Download a version of LÖVE")]
Download {
#[structopt(possible_values=&LoveVersion::variants())]
#[structopt(possible_values=LOVE_VERSIONS)]
version: LoveVersion,
},
#[structopt(about = "Remove a version of LÖVE")]
Remove {
#[structopt(possible_values=&LoveVersion::variants())]
#[structopt(possible_values=LOVE_VERSIONS)]
version: LoveVersion,
},
#[structopt(about = "List installed LÖVE versions")]
Expand Down
9 changes: 2 additions & 7 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub enum Bitness {
X64, // 64 bit
}

const LOVE_VERSIONS: [&str; 6] = ["11.5", "11.4", "11.3", "11.2", "11.1", "11.0", "0.10.2"];
pub static LOVE_VERSIONS: &[&str] = &["11.5", "11.4", "11.3", "11.2", "11.1", "11.0", "0.10.2"];

/// Represents a specific version of LÖVE2D
#[derive(Copy, Clone, Debug, Primitive)]
pub enum LoveVersion {
Expand Down Expand Up @@ -87,12 +88,6 @@ impl FromStr for LoveVersion {
}
}

impl LoveVersion {
pub const fn variants() -> [&'static str; 6] {
LOVE_VERSIONS
}
}

impl Display for LoveVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", LOVE_VERSIONS[*self as usize])
Expand Down

0 comments on commit e34fc0e

Please sign in to comment.