Skip to content

Commit

Permalink
impl display for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Nov 7, 2024
1 parent 098b45d commit eb5a1fc
Showing 1 changed file with 62 additions and 30 deletions.
92 changes: 62 additions & 30 deletions workspace/gh-workflow/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,53 @@ pub enum Component {
RustDoc,
}

impl Display for Component {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let val = match self {
Component::Clippy => "clippy",
Component::Rustfmt => "rustfmt",
Component::RustDoc => "rust-doc",
};
write!(f, "{}", val)
}
}

#[derive(Clone)]
pub enum Arch {
X86_64,
Aarch64,
Arm,
}

impl Display for Arch {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let val = match self {
Arch::X86_64 => "x86_64",
Arch::Aarch64 => "aarch64",
Arch::Arm => "arm",
};
write!(f, "{}", val)
}
}

#[derive(Clone)]
pub enum Vendor {
Unknown,
Apple,
PC,
}

impl Display for Vendor {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let val = match self {
Vendor::Unknown => "unknown",
Vendor::Apple => "apple",
Vendor::PC => "pc",
};
write!(f, "{}", val)
}
}

#[derive(Clone)]
pub enum System {
Unknown,
Expand All @@ -58,6 +91,18 @@ pub enum System {
Darwin,
}

impl Display for System {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let val = match self {
System::Unknown => "unknown",
System::Windows => "windows",
System::Linux => "linux",
System::Darwin => "darwin",
};
write!(f, "{}", val)
}
}

#[derive(Clone)]
pub enum Abi {
Unknown,
Expand All @@ -66,6 +111,18 @@ pub enum Abi {
Musl,
}

impl Display for Abi {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let val = match self {
Abi::Unknown => "unknown",
Abi::Gnu => "gnu",
Abi::Msvc => "msvc",
Abi::Musl => "musl",
};
write!(f, "{}", val)
}
}

#[derive(Clone, Setters)]
pub struct Target {
arch: Arch,
Expand Down Expand Up @@ -124,31 +181,10 @@ impl AddStep for ToolchainStep {
if let Some(target) = self.target {
let target = format!(
"{}-{}-{}{}",
match target.arch {
Arch::X86_64 => "x86_64",
Arch::Aarch64 => "aarch64",
Arch::Arm => "arm",
},
match target.vendor {
Vendor::Unknown => "unknown",
Vendor::Apple => "apple",
Vendor::PC => "pc",
},
match target.system {
System::Unknown => "unknown",
System::Windows => "windows",
System::Linux => "linux",
System::Darwin => "darwin",
},
match target.abi {
Some(abi) => match abi {
Abi::Unknown => "unknown",
Abi::Gnu => "gnu",
Abi::Msvc => "msvc",
Abi::Musl => "musl",
},
None => "",
}
target.arch.to_string(),
target.vendor.to_string(),
target.system.to_string(),
target.abi.map(|v| v.to_string()).unwrap_or_default(),
);

step = step.with(("target", target));
Expand All @@ -158,11 +194,7 @@ impl AddStep for ToolchainStep {
let components = self
.components
.iter()
.map(|c| match c {
Component::Clippy => "clippy".to_string(),
Component::Rustfmt => "rustfmt".to_string(),
Component::RustDoc => "rust-doc".to_string(),
})
.map(|c| c.to_string())
.fold("".to_string(), |acc, a| format!("{},{}", acc, a));

step = step.with(("components", components));
Expand Down

0 comments on commit eb5a1fc

Please sign in to comment.