Skip to content

Commit 39774f1

Browse files
committed
docs, cleanups
1 parent c96b613 commit 39774f1

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

crates/cargo-gpu/src/show.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
use std::fs;
44

5-
use anyhow::Context;
6-
75
use crate::cache_dir;
86

97
/// Show the computed source of the spirv-std dependency.
@@ -89,12 +87,12 @@ impl Show {
8987
(0..=last_capability).filter_map(spirv_builder::Capability::from_u32)
9088
}
9189

92-
// List all available spirv targets, note: the targets from compile time of cargo-gpu and those
93-
// in the cache-directory will be picked up.
90+
/// List all available spirv targets, note: the targets from compile time of cargo-gpu and those
91+
/// in the cache-directory will be picked up.
9492
fn available_spirv_targets_iter() -> anyhow::Result<impl Iterator<Item = String>> {
9593
let legacy_targets = legacy_target_specs::TARGET_SPECS
9694
.iter()
97-
.map(|(spec, _src)| spec.to_string()); // Convert to String
95+
.map(|(spec, _src)| (*spec).to_string());
9896

9997
let cache_dir = cache_dir()?;
10098
if !cache_dir.exists() {
@@ -103,29 +101,28 @@ impl Show {
103101
cache_dir.display()
104102
);
105103
}
106-
107104
let entries = fs::read_dir(&cache_dir)?;
108-
109105
let cached_targets: Vec<String> = entries
110-
.filter_map(|entry| entry.ok())
106+
.flatten()
111107
.flat_map(|entry| {
112108
let path = entry.path();
113109
if path.is_dir() {
114110
fs::read_dir(path)
115111
.ok()
116112
.into_iter()
117113
.flatten()
118-
.filter_map(|e| e.ok())
119-
.filter_map(|e| {
120-
e.path()
114+
.filter_map(Result::ok)
115+
.filter_map(|entry| {
116+
entry
117+
.path()
121118
.file_stem()
122-
.and_then(|s| s.to_str())
119+
.and_then(std::ffi::OsStr::to_str)
123120
.map(str::to_owned)
124121
})
125122
.collect::<Vec<_>>()
126-
} else if path.extension().and_then(|s| s.to_str()) == Some("json") {
123+
} else if path.extension().and_then(std::ffi::OsStr::to_str) == Some("json") {
127124
path.file_stem()
128-
.and_then(|s| s.to_str())
125+
.and_then(std::ffi::OsStr::to_str)
129126
.map(str::to_owned)
130127
.into_iter()
131128
.collect()
@@ -134,21 +131,18 @@ impl Show {
134131
}
135132
})
136133
.collect();
137-
138134
if cached_targets.is_empty() {
139135
log::error!(
140136
"Cache directory exists but contains no valid SPIR-V target files (*.json): {}",
141137
cache_dir.display()
142138
);
143139
}
144-
145140
let mut targets: Vec<String> = legacy_targets
146141
.chain(cached_targets)
147-
.filter(|t| t.contains("vulkan"))
142+
.filter(|target| target.contains("vulkan"))
148143
.collect::<std::collections::HashSet<_>>()
149144
.into_iter()
150145
.collect();
151-
152146
targets.sort();
153147
Ok(targets.into_iter())
154148
}

0 commit comments

Comments
 (0)