Skip to content

Commit b02e06f

Browse files
committed
refactor(names): replace maybe_official_toolchainame_parser with impl FromStr
1 parent 0a72c68 commit b02e06f

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/cli/setup_mode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
currentprocess::{argsource::ArgSource, filesource::StdoutSource},
1010
dist::dist::Profile,
1111
process,
12-
toolchain::names::{maybe_official_toolchainame_parser, MaybeOfficialToolchainName},
12+
toolchain::names::MaybeOfficialToolchainName,
1313
utils::utils,
1414
};
1515

@@ -66,7 +66,6 @@ pub fn main() -> Result<utils::ExitCode> {
6666
.long("default-toolchain")
6767
.num_args(1)
6868
.help("Choose a default toolchain to install. Use 'none' to not install any toolchains at all")
69-
.value_parser(maybe_official_toolchainame_parser)
7069
)
7170
.arg(
7271
Arg::new("profile")

src/toolchain/names.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ macro_rules! try_from_str {
9595
$to::validate(&value)
9696
}
9797
}
98+
99+
impl FromStr for $to {
100+
type Err = InvalidName;
101+
102+
fn from_str(value: &str) -> std::result::Result<Self, Self::Err> {
103+
$to::validate(value)
104+
}
105+
}
98106
};
99107
($from:ty, $to:ident) => {
100108
impl TryFrom<$from> for $to {
@@ -264,15 +272,6 @@ impl Display for MaybeOfficialToolchainName {
264272
}
265273
}
266274

267-
/// Thunk to avoid errors like
268-
/// = 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`...
269-
/// = note: ...but it actually implements `FnOnce<(&'2 str,)>`, for some specific lifetime `'2`
270-
pub(crate) fn maybe_official_toolchainame_parser(
271-
value: &str,
272-
) -> Result<MaybeOfficialToolchainName, InvalidName> {
273-
MaybeOfficialToolchainName::try_from(value)
274-
}
275-
276275
/// ToolchainName can be used in calls to Cfg that alter configuration,
277276
/// like setting overrides, or that depend on configuration, like calculating
278277
/// the toolchain directory.

0 commit comments

Comments
 (0)