Skip to content

Commit 9fd0ecf

Browse files
authored
Merge pull request #99 from olback/clippy
make clippy happy
2 parents 4fcb86c + feb0e4b commit 9fd0ecf

File tree

13 files changed

+79
-87
lines changed

13 files changed

+79
-87
lines changed

ll-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() -> ll_core::Result<()> {
3232
Config::default_path()
3333
} else {
3434
app.value_of("config")
35-
.map(|p| PathBuf::from(p))
35+
.map(PathBuf::from)
3636
.or(Config::get_path()?)
3737
} {
3838
Some(path) => path,

ll-core/src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Config {
6262

6363
fn path(path: Option<PathBuf>) -> Result<PathBuf> {
6464
path.or(Self::default_path())
65-
.ok_or(Error::Other("Could not find config dir".into()))
65+
.ok_or(Error::Other("Could not find config dir"))
6666
}
6767

6868
pub fn default_path() -> Option<PathBuf> {

ll-core/src/cse/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use {
1212
mod result;
1313
pub use result::Result;
1414

15+
#[allow(clippy::upper_case_acronyms)]
1516
pub struct CSE {
1617
auth: String,
1718
formats: Arc<Vec<Format>>,
@@ -66,7 +67,7 @@ impl CSE {
6667
.replace("attachment;", "")
6768
.trim()
6869
.replace("filename=", "")
69-
.replace("\"", "")
70+
.replace('"', "")
7071
.trim()
7172
.to_string()
7273
}

ll-core/src/cse/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Result {
1616
pub fn save(&self) -> error::Result<PathBuf> {
1717
let save_dir = Path::new(&self.output_path);
1818

19-
if &self.files.len() > &0 {
19+
if !self.files.is_empty() {
2020
if !save_dir.exists() {
2121
fs::create_dir_all(save_dir)?;
2222
}
@@ -39,7 +39,7 @@ impl Result {
3939
return Err(Error::WouldOverwrite);
4040
}
4141

42-
fs::write(&path, &data)?;
42+
fs::write(&path, data)?;
4343
Ok(path)
4444
}
4545
}

ll-core/src/epw.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ impl Epw {
4343
};
4444

4545
for line in lines {
46-
let line_parts: Vec<&str> = line.split("=").collect();
46+
let line_parts: Vec<&str> = line.split('=').collect();
4747

4848
if line_parts.len() == 2 {
4949
map.insert(line_parts[0], line_parts[1]);
5050
}
5151
}
5252

5353
Ok(Self {
54-
id: id,
54+
id,
5555
mna: String::from(*map.get("mna").unwrap_or(&"")),
5656
mpn: String::from(*map.get("mpn").unwrap_or(&"")),
5757
pna: String::from(*map.get("pna").unwrap_or(&"")),
@@ -82,7 +82,7 @@ impl Epw {
8282
fn from_zip(raw_data: Vec<u8>) -> Result<Self> {
8383
// The zip library crashes if the archive is empty,
8484
// lets prevent that.
85-
if raw_data.len() == 0 {
85+
if raw_data.is_empty() {
8686
return Err(Error::ZipArchiveEmpty);
8787
}
8888

ll-core/src/format/extractors/kicad.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn extract(
7272
let footprint_name = &parts[2][1..(parts[2].len() - 1)];
7373
lines[i] = lines[i].replace(
7474
footprint_name,
75-
&*format!("{}:{}", format.name, &footprint_name),
75+
&format!("{}:{}", format.name, &footprint_name),
7676
);
7777
}
7878
}

ll-core/src/format/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ impl Format {
104104
//no changes
105105
}
106106
}
107-
return fmt;
107+
108+
fmt
108109
}
109110

110111
pub fn extract(
@@ -114,9 +115,9 @@ impl Format {
114115
Ok(match &self.ecad {
115116
// * Keep these in alphabetical order
116117
ECAD::D3 | ECAD::DesignSpark | ECAD::Eagle | ECAD::EasyEDA => {
117-
generic_extractor(&self, archive)?
118+
generic_extractor(self, archive)?
118119
}
119-
ECAD::KiCad => extractors::kicad::extract(&self, archive)?,
120+
ECAD::KiCad => extractors::kicad::extract(self, archive)?,
120121
ECAD::Zip => unreachable!("ZIP not handled!"),
121122
// ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
122123
})

ll-core/src/updates/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use {
22
crate::{consts, error::Result},
3-
reqwest,
43
serde::Deserialize,
54
};
65

@@ -24,7 +23,7 @@ pub struct UpdateInfo<'l, 'u> {
2423
pub url: &'u str,
2524
}
2625

27-
pub fn check<'l>(local_version: &'l str, kind: ClientKind) -> Result<Option<UpdateInfo>> {
26+
pub fn check(local_version: &str, kind: ClientKind) -> Result<Option<UpdateInfo>> {
2827
let url = format!(
2928
"https://raw.githubusercontent.com/olback/library-loader/master/{kind}/Cargo.toml",
3029
kind = kind

ll-core/src/watcher/mod.rs

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,46 @@ impl Watcher {
6363
match rx.recv() {
6464
Ok(WatcherEvent::NotifyResult(Ok(event))) => {
6565
// log_info!(&*loggers, format!("{:#?}", event));
66-
match event.kind {
67-
NotifyEventKind::Create(NotifyCreateKind::File) => {
68-
// println!("evt: {:#?}", event);
69-
for file in event.paths {
70-
if file.extension().map(|e| e.to_ascii_lowercase())
71-
== Some(OsString::from("zip"))
72-
{
73-
log_info!(&*loggers, format!("Detected {:?}", file));
74-
let token = token.clone();
75-
let formats = Arc::clone(&formats);
76-
let loggers_clone = Arc::clone(&loggers);
77-
// uuuh
78-
std::thread::sleep(std::time::Duration::from_millis(100));
79-
match (move || -> Result<()> {
80-
let epw = Epw::from_file(file)?;
81-
for res in CSE::new(token, formats).get(epw)? {
82-
match res.save() {
83-
Ok(save_path) => {
84-
log_info!(
85-
&*loggers_clone,
86-
format!("Saved to {:?}", save_path)
87-
)
88-
}
89-
Err(e) => {
90-
log_error!(&*loggers_clone, e)
91-
}
66+
67+
if let NotifyEventKind::Create(NotifyCreateKind::File) = event.kind {
68+
// println!("evt: {:#?}", event);
69+
for file in event.paths {
70+
if file.extension().map(|e| e.to_ascii_lowercase())
71+
== Some(OsString::from("zip"))
72+
{
73+
log_info!(&*loggers, format!("Detected {:?}", file));
74+
let token = token.clone();
75+
let formats = Arc::clone(&formats);
76+
let loggers_clone = Arc::clone(&loggers);
77+
// uuuh
78+
std::thread::sleep(std::time::Duration::from_millis(100));
79+
match (move || -> Result<()> {
80+
let epw = Epw::from_file(file)?;
81+
for res in CSE::new(token, formats).get(epw)? {
82+
match res.save() {
83+
Ok(save_path) => {
84+
log_info!(
85+
&*loggers_clone,
86+
format!("Saved to {:?}", save_path)
87+
)
88+
}
89+
Err(e) => {
90+
log_error!(&*loggers_clone, e)
9291
}
9392
}
94-
Ok(())
95-
})() {
96-
Ok(()) => {
97-
log_info!(&*loggers, "Done");
98-
}
99-
Err(e) => {
100-
log_error!(&*loggers, format!("{:?}", e));
101-
}
93+
}
94+
Ok(())
95+
})() {
96+
Ok(()) => {
97+
log_info!(&*loggers, "Done");
98+
}
99+
Err(e) => {
100+
log_error!(&*loggers, format!("{:?}", e));
102101
}
103102
}
104103
}
105-
// log_info!(&*loggers, format!("{:#?}", event));
106104
}
107-
_ => {}
105+
// log_info!(&*loggers, format!("{:#?}", event));
108106
}
109107
}
110108
Ok(WatcherEvent::NotifyResult(Err(error))) => {
@@ -145,17 +143,14 @@ impl Watcher {
145143
}
146144

147145
pub fn stop(&mut self) {
148-
match self.thread.take() {
149-
Some((jh, tx, mut w)) => {
150-
log_if_error!(&*self.loggers, w.unwatch(self.watch_path.as_path()));
151-
log_if_error!(&*self.loggers, tx.send(WatcherEvent::Stop));
152-
log_if_error!(&*self.loggers, jh.join());
153-
log_info!(
154-
&*self.loggers,
155-
format!("Stopped watching {:?}", self.watch_path)
156-
);
157-
}
158-
None => {}
146+
if let Some((jh, tx, mut w)) = self.thread.take() {
147+
log_if_error!(&*self.loggers, w.unwatch(self.watch_path.as_path()));
148+
log_if_error!(&*self.loggers, tx.send(WatcherEvent::Stop));
149+
log_if_error!(&*self.loggers, jh.join());
150+
log_info!(
151+
&*self.loggers,
152+
format!("Stopped watching {:?}", self.watch_path)
153+
);
159154
}
160155
}
161156
}

ll-gui/build/glade.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use regex;
21
use std::fs;
32

43
pub fn fix_resource_paths() {
@@ -13,9 +12,9 @@ pub fn fix_resource_paths() {
1312
.replace(
1413
"{{authors}}",
1514
&env!("CARGO_PKG_AUTHORS")
16-
.replace(":", "\n")
17-
.replace("<", "&lt;")
18-
.replace(">", "&gt;"),
15+
.replace(':', "\n")
16+
.replace('<', "&lt;")
17+
.replace('>', "&gt;"),
1918
)
2019
.replace("{{version}}", env!("CARGO_PKG_VERSION"));
2120

ll-gui/build/resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn generate_resources() {
1111
}
1212

1313
let resources = Command::new(COMMAND)
14-
.args(&[INPUT, &format!("--target=out/{}", TARGET)])
14+
.args([INPUT, &format!("--target=out/{}", TARGET)])
1515
.output()
1616
.unwrap();
1717

ll-gui/build/windows.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn generate_rc() {
3636
pub fn compile_rc() {
3737
let out_dir = env::var("OUT_DIR").unwrap();
3838
match Command::new("x86_64-w64-mingw32-windres")
39-
.args(&["out/library-loader.rc", &format!("{}/program.o", out_dir)])
39+
.args(["out/library-loader.rc", &format!("{}/program.o", out_dir)])
4040
.status()
4141
{
4242
Ok(s) => {
@@ -59,8 +59,8 @@ pub fn compile_rc() {
5959
};
6060

6161
match Command::new("x86_64-w64-mingw32-gcc-ar")
62-
.args(&["crus", "libprogram.a", "program.o"])
63-
.current_dir(&Path::new(&out_dir))
62+
.args(["crus", "libprogram.a", "program.o"])
63+
.current_dir(Path::new(&out_dir))
6464
.status()
6565
{
6666
Ok(s) => {

ll-gui/src/ui/mod.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Ui {
116116
box2.set_spacing(6);
117117
box2.set_hexpand(true);
118118
box2.set_hexpand_set(true);
119-
let label1 = Label::new(Some(&name));
119+
let label1 = Label::new(Some(name));
120120
label1.set_halign(Align::Start);
121121
label1.set_xalign(0.0);
122122
label1.style_context().add_class("format-title");
@@ -186,7 +186,7 @@ impl Ui {
186186
.as_ref(),
187187
)));
188188
watch_path_chooser.connect_file_set(clone!(@strong inner => move |btn| {
189-
if let Some(p) = btn.file().map(|f| f.path()).flatten() {
189+
if let Some(p) = btn.file().and_then(|f| f.path()) {
190190
inner.config.borrow_mut().settings.watch_path = p.to_str().unwrap().to_string();
191191
}
192192
}));
@@ -206,22 +206,19 @@ impl Ui {
206206
if inner.add_format_dialog.run() == ResponseType::Ok {
207207
let name = inner.add_format_name.text().to_string().trim().to_string();
208208
let format = inner.add_format_format.active_id().map(|f| f.to_string());
209-
let file = inner.add_format_output.file().map(|f| f.path()).flatten();
210-
match (name.is_empty(), format, file) {
211-
(false, Some(format), Some(file)) => {
212-
let mut conf = inner.config.borrow_mut();
213-
if conf.formats.get(&name).is_none() {
214-
use std::convert::TryFrom;
215-
conf.formats.insert(name, Format {
216-
format: ECAD::try_from(format.as_str()).expect("Invalid ECAD type in glade file"),
217-
output_path: file.to_str().unwrap().to_string()
218-
});
219-
drop(inner.tx.send(UiEvent::UpdateFormats));
220-
} else {
221-
drop(inner.tx.send(UiEvent::ShowInfoBar(format!("Format with name '{}' already exists", name), MessageType::Error)));
222-
}
223-
},
224-
_ => {}
209+
let file = inner.add_format_output.file().and_then(|f| f.path());
210+
if let (false, Some(format), Some(file)) = (name.is_empty(), format, file) {
211+
let mut conf = inner.config.borrow_mut();
212+
if conf.formats.get(&name).is_none() {
213+
use std::convert::TryFrom;
214+
conf.formats.insert(name, Format {
215+
format: ECAD::try_from(format.as_str()).expect("Invalid ECAD type in glade file"),
216+
output_path: file.to_str().unwrap().to_string()
217+
});
218+
drop(inner.tx.send(UiEvent::UpdateFormats));
219+
} else {
220+
drop(inner.tx.send(UiEvent::ShowInfoBar(format!("Format with name '{}' already exists", name), MessageType::Error)));
221+
}
225222
}
226223
}
227224
inner.add_format_dialog.hide();

0 commit comments

Comments
 (0)