Skip to content

Commit

Permalink
refactor(names): replace maybe_official_toolchainame_parser with `i…
Browse files Browse the repository at this point in the history
…mpl FromStr`
  • Loading branch information
rami3l committed Jan 19, 2024
1 parent 0a72c68 commit b02e06f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
currentprocess::{argsource::ArgSource, filesource::StdoutSource},
dist::dist::Profile,
process,
toolchain::names::{maybe_official_toolchainame_parser, MaybeOfficialToolchainName},
toolchain::names::MaybeOfficialToolchainName,
utils::utils,
};

Expand Down Expand Up @@ -66,7 +66,6 @@ pub fn main() -> Result<utils::ExitCode> {
.long("default-toolchain")
.num_args(1)
.help("Choose a default toolchain to install. Use 'none' to not install any toolchains at all")
.value_parser(maybe_official_toolchainame_parser)
)
.arg(
Arg::new("profile")
Expand Down
17 changes: 8 additions & 9 deletions src/toolchain/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ macro_rules! try_from_str {
$to::validate(&value)
}
}

impl FromStr for $to {
type Err = InvalidName;

fn from_str(value: &str) -> std::result::Result<Self, Self::Err> {
$to::validate(value)
}
}
};
($from:ty, $to:ident) => {
impl TryFrom<$from> for $to {
Expand Down Expand Up @@ -264,15 +272,6 @@ impl Display for MaybeOfficialToolchainName {
}
}

/// Thunk to avoid errors like
/// = note: `fn(&'2 str) -> Result<CustomToolchainName, <CustomToolchainName as TryFrom<&'2 str>>::Error> {<CustomToolchainName as TryFrom<&'2 str>>::try_from}` must implement `FnOnce<(&'1 str,)>`, for any lifetime `'1`...
/// = note: ...but it actually implements `FnOnce<(&'2 str,)>`, for some specific lifetime `'2`
pub(crate) fn maybe_official_toolchainame_parser(
value: &str,
) -> Result<MaybeOfficialToolchainName, InvalidName> {
MaybeOfficialToolchainName::try_from(value)
}

/// ToolchainName can be used in calls to Cfg that alter configuration,
/// like setting overrides, or that depend on configuration, like calculating
/// the toolchain directory.
Expand Down

0 comments on commit b02e06f

Please sign in to comment.