Skip to content

Commit f06cb34

Browse files
committed
Replace TargetKind with simple String
1 parent a5b647f commit f06cb34

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

src/bin/cargo-fmt.rs

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ fn format_crate(
137137
// Currently only bin and lib files get formatted
138138
let files: Vec<_> = targets
139139
.into_iter()
140-
.filter(|t| t.kind.should_format())
141140
.inspect(|t| {
142141
if verbosity == Verbosity::Verbose {
143-
println!("[{:?}] {:?}", t.kind, t.path)
142+
println!("[{}] {:?}", t.kind, t.path)
144143
}
145144
})
146145
.map(|t| t.path)
@@ -154,53 +153,13 @@ fn get_fmt_args() -> Vec<String> {
154153
env::args().skip_while(|a| a != "--").skip(1).collect()
155154
}
156155

157-
#[derive(Debug)]
158-
enum TargetKind {
159-
Lib, // dylib, staticlib, lib
160-
Bin, // bin
161-
Example, // example file
162-
Test, // test file
163-
Bench, // bench file
164-
CustomBuild, // build script
165-
ProcMacro, // a proc macro implementation
166-
Other, // plugin,...
167-
}
168-
169-
impl TargetKind {
170-
fn should_format(&self) -> bool {
171-
match *self {
172-
TargetKind::Lib
173-
| TargetKind::Bin
174-
| TargetKind::Example
175-
| TargetKind::Test
176-
| TargetKind::Bench
177-
| TargetKind::CustomBuild
178-
| TargetKind::ProcMacro => true,
179-
_ => false,
180-
}
181-
}
182-
183-
fn from_str(s: &str) -> Self {
184-
match s {
185-
"bin" => TargetKind::Bin,
186-
"lib" | "dylib" | "staticlib" | "cdylib" | "rlib" => TargetKind::Lib,
187-
"test" => TargetKind::Test,
188-
"example" => TargetKind::Example,
189-
"bench" => TargetKind::Bench,
190-
"custom-build" => TargetKind::CustomBuild,
191-
"proc-macro" => TargetKind::ProcMacro,
192-
_ => TargetKind::Other,
193-
}
194-
}
195-
}
196-
197156
/// Target uses a `path` field for equality and hashing.
198157
#[derive(Debug)]
199158
pub struct Target {
200159
/// A path to the main source file of the target.
201160
path: PathBuf,
202161
/// A kind of target (e.g. lib, bin, example, ...).
203-
kind: TargetKind,
162+
kind: String,
204163
}
205164

206165
impl Target {
@@ -210,7 +169,7 @@ impl Target {
210169

211170
Target {
212171
path: canonicalized,
213-
kind: TargetKind::from_str(&target.kind[0]),
172+
kind: target.kind[0].clone(),
214173
}
215174
}
216175
}

0 commit comments

Comments
 (0)