Skip to content

Commit df94557

Browse files
committed
Fix clippy lints
1 parent e986fb3 commit df94557

File tree

5 files changed

+45
-41
lines changed

5 files changed

+45
-41
lines changed

gemini/src/client.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,28 @@ impl Client {
123123
options: Default::default(),
124124
}
125125
}
126-
pub async fn fetch(&self, url: &str) -> Result<Response, Error> {
127-
let url = Url::parse(url)?;
128-
let mut res = Self::fetch_internal(url).await?;
129-
if self.options.redirect {
130-
let mut n_redirect: u8 = 0;
131-
loop {
132-
match res.status {
133-
Status::Redirect(_) => {
134-
let url = Url::parse(res.meta())?;
135-
res = Self::fetch_internal(url).await?;
136-
n_redirect += 1;
137-
}
138-
_ => break,
139-
}
140-
if n_redirect > MAX_REDIRECT {
141-
return Err(Error::TooManyRedirects(res.meta_owned()));
126+
pub async fn fetch(&self, url_str: &str) -> Result<Response, Error> {
127+
let mut url_str = url_str;
128+
let mut res;
129+
let mut i = 0;
130+
let max_redirect = if self.options.redirect {
131+
MAX_REDIRECT
132+
} else {
133+
1
134+
};
135+
while {
136+
let url = Url::parse(url_str)?;
137+
res = Self::fetch_internal(url).await?;
138+
i < max_redirect
139+
} {
140+
match res.status() {
141+
Status::Redirect(_) => {
142+
url_str = res.meta();
143+
i += 1;
142144
}
145+
_ => break,
143146
}
144147
}
145-
146148
Ok(res)
147149
}
148150
async fn fetch_internal(url: Url) -> Result<Response, Error> {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async fn read_config() -> anyhow::Result<config::Config> {
2626
}
2727
async fn create_dir_if_not_exists(path: &std::path::Path) -> anyhow::Result<()> {
2828
if !path.exists() {
29-
async_fs::create_dir_all(&*path)
29+
async_fs::create_dir_all(path)
3030
.await
3131
.context(format!("Failed to create directory {:?}", path))?
3232
}

src/widgets/pages/hypertext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl Hypertext {
423423
let (x, y) =
424424
text_view.window_to_buffer_coords(gtk::TextWindowType::Widget, x as i32, y as i32);
425425
let iter = text_view
426-
.iter_at_location(x as i32, y as i32)
426+
.iter_at_location(x, y)
427427
.context("Can't get text iter where clicked")?;
428428

429429
iter.tags()
@@ -441,7 +441,7 @@ impl Hypertext {
441441
}
442442
let url = {
443443
let links = imp.links.borrow();
444-
let (_, link) = Self::extract_linkhandler(&*links, text_view, x, y)?;
444+
let (_, link) = Self::extract_linkhandler(&links, text_view, x, y)?;
445445
self.parse_link(link)?
446446
};
447447
if ctrl
@@ -464,7 +464,7 @@ impl Hypertext {
464464

465465
let link = {
466466
let links = imp.links.borrow();
467-
let (_, link) = Self::extract_linkhandler(&*links, text_view, x, y)?;
467+
let (_, link) = Self::extract_linkhandler(&links, text_view, x, y)?;
468468
self.parse_link(link)?
469469
};
470470
let link_variant = link.as_str().to_variant();
@@ -489,7 +489,7 @@ impl Hypertext {
489489
let text_view = &surface.as_ref().unwrap().text_view;
490490

491491
let links = imp.links.borrow();
492-
let entry = Self::extract_linkhandler(&*links, text_view, x, y);
492+
let entry = Self::extract_linkhandler(&links, text_view, x, y);
493493

494494
let link_ref = entry.as_ref().map(|x| x.1).unwrap_or("");
495495
if link_ref == *imp.hover_url.borrow() {

src/widgets/tab.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use anyhow::{bail, Context, Result};
22
use async_fs::File;
3-
use async_trait::async_trait;
43
use futures::future::RemoteHandle;
54
use futures::io::BufReader;
65
use futures::prelude::*;
@@ -12,7 +11,7 @@ use gtk::prelude::*;
1211
use gtk::subclass::prelude::*;
1312
use gtk::CompositeTemplate;
1413
use gtk::TemplateChild;
15-
use log::{debug, info, warn};
14+
use log::{debug, info};
1615
use once_cell::sync::Lazy;
1716
use std::cell::{Cell, Ref, RefCell};
1817
use std::fmt::Write;
@@ -247,7 +246,7 @@ impl Tab {
247246
fn open_url(&self, url: Url) -> impl Future<Output = Option<Vec<u8>>> {
248247
let imp = self.imp();
249248

250-
self.set_progress(&0.0);
249+
self.set_progress(0.0);
251250
*imp.title.borrow_mut() = url.to_string();
252251
self.emit_title();
253252
*imp.url.borrow_mut() = url.to_string();
@@ -269,10 +268,10 @@ impl Tab {
269268
None
270269
}
271270
};
272-
this.set_progress(&1.0);
271+
this.set_progress(1.0);
273272
cache
274273
};
275-
self.set_progress(&0.3);
274+
self.set_progress(0.3);
276275
fut
277276
}
278277
fn open_history(&self, item: HistoryItem) -> Pin<Box<dyn Future<Output = ()>>> {
@@ -681,7 +680,7 @@ impl Tab {
681680
let new_index = if offset > 0 {
682681
h.index().unwrap_or(0) + offset as usize
683682
} else {
684-
h.index().unwrap_or(0).saturating_sub(offset.abs() as usize)
683+
h.index().unwrap_or(0).saturating_sub(offset.unsigned_abs())
685684
};
686685
h.index() != Some(new_index) && h.set_index(new_index)
687686
};

src/widgets/window.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use gtk::subclass::prelude::*;
1212
use gtk::CompositeTemplate;
1313
use gtk::TemplateChild;
1414
use log::{error, info, warn};
15-
use std::cell::{Ref, RefCell};
15+
use std::cell::RefCell;
1616
use std::hash::{Hash, Hasher};
1717
use std::marker::PhantomData;
1818
use url::Url;
@@ -407,23 +407,26 @@ impl Window {
407407
);
408408
popover.add_child(&zoom_box, "zoom");
409409
}
410-
fn setup_history_button(
410+
fn setup_history_button<
411+
F: for<'a> Fn(
412+
&'a [HistoryItem],
413+
usize,
414+
) -> Box<dyn Iterator<Item = (isize, &'a HistoryItem)> + 'a>
415+
+ 'static,
416+
>(
411417
&self,
412418
p: gtk::Popover,
413419
btn: gtk::Button,
414-
f: for<'a> fn(
415-
&'a [HistoryItem],
416-
usize,
417-
) -> Box<dyn Iterator<Item = (isize, &'a HistoryItem)> + 'a>,
420+
f: F,
418421
) {
419422
let ctrl = gtk::GestureClick::builder().button(3).build();
420423

421424
let this = self.downgrade();
422-
ctrl.connect_pressed(move |_, n, x, y| {
425+
ctrl.connect_pressed(move |_, _, _, _| {
423426
let this = this.upgrade().unwrap();
424427
let tab = this.current_tab();
425428
let items = tab.history_items();
426-
let items = f(&*items, tab.history_status().current);
429+
let items = f(&items, tab.history_status().current);
427430
let b = gtk::Box::new(gtk::Orientation::Vertical, 0);
428431
for (offset, item) in items {
429432
let label = gtk::Label::new(Some(item.url.as_str()));
@@ -561,9 +564,9 @@ impl Window {
561564
fn active_url_bar(&self) -> &gtk::SearchEntry {
562565
let imp = self.imp();
563566
if self.is_small_screen() {
564-
&*imp.small_url_bar
567+
&imp.small_url_bar
565568
} else {
566-
&*imp.url_bar
569+
&imp.url_bar
567570
}
568571
}
569572
fn focus_url_bar(&self) {
@@ -750,12 +753,12 @@ impl Window {
750753
}
751754

752755
fn zoom_in(&self) {
753-
self.set_zoom(&(self.zoom() * ZOOM_CHANGE_FACTOR));
756+
self.set_zoom(self.zoom() * ZOOM_CHANGE_FACTOR);
754757
}
755758
fn zoom_out(&self) {
756-
self.set_zoom(&(self.zoom() * 1.0 / ZOOM_CHANGE_FACTOR));
759+
self.set_zoom(self.zoom() * 1.0 / ZOOM_CHANGE_FACTOR);
757760
}
758761
fn reset_zoom(&self) {
759-
self.set_zoom(&1.0);
762+
self.set_zoom(1.0);
760763
}
761764
}

0 commit comments

Comments
 (0)