Use default rust formatting

This commit is contained in:
Markus Kohlhase 2023-09-15 15:25:39 +02:00
parent ed163b9a42
commit a1c38dbc9a
20 changed files with 1104 additions and 1102 deletions

View file

@ -1,3 +0,0 @@
indent_style = "Block"
reorder_imports = true
tab_spaces = 2

View file

@ -46,7 +46,9 @@ pub async fn parse_head(
.and_then(|href| url.join(&href).ok()) .and_then(|href| url.join(&href).ok())
{ {
new_icons.borrow_mut().push( new_icons.borrow_mut().push(
async { SiteIcons::load_manifest(href).await.unwrap_or(Vec::new()) } async {
SiteIcons::load_manifest(href).await.unwrap_or(Vec::new())
}
.boxed_local() .boxed_local()
.shared(), .shared(),
) )

View file

@ -24,7 +24,8 @@ pub async fn parse_site_logo(
let document = parser.finish(); let document = parser.finish();
let mut logos: Vec<_> = document let mut logos: Vec<_> =
document
.select(selector!( .select(selector!(
"a[href='/'] img, a[href='/'] svg", "a[href='/'] img, a[href='/'] svg",
"header img, header svg", "header img, header svg",
@ -108,11 +109,9 @@ pub async fn parse_site_logo(
.and_then(|domain| TldOption::default().build().extract(domain).unwrap().domain) .and_then(|domain| TldOption::default().build().extract(domain).unwrap().domain)
{ {
// if the alt contains the site_name then highest priority // if the alt contains the site_name then highest priority
if site_name if site_name.to_lowercase().split('-').any(|segment| {
.to_lowercase() mentions("alt", Box::new(move |attr| attr.contains(segment)))
.split('-') }) {
.any(|segment| mentions("alt", Box::new(move |attr| attr.contains(segment))))
{
weight += 10; weight += 10;
} }
} }

View file

@ -84,8 +84,7 @@ impl IconInfo {
let mime = url.mime_type().to_string().parse::<MediaType>()?; let mime = url.mime_type().to_string().parse::<MediaType>()?;
let body = Cursor::new( let body = Cursor::new(
url url.decode_to_vec()
.decode_to_vec()
.map_err(|_| "failed to decode data uri body")? .map_err(|_| "failed to decode data uri body")?
.0, .0,
); );
@ -115,7 +114,9 @@ impl IconInfo {
let body = res let body = res
.bytes_stream() .bytes_stream()
.map(|result| { .map(|result| {
result.map_err(|error| io::Error::new(io::ErrorKind::Other, error.to_string())) result.map_err(|error| {
io::Error::new(io::ErrorKind::Other, error.to_string())
})
}) })
.into_async_read(); .into_async_read();
@ -230,12 +231,14 @@ impl Display for IconInfo {
impl Ord for IconInfo { impl Ord for IconInfo {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
match (self, other) { match (self, other) {
(IconInfo::SVG { size }, IconInfo::SVG { size: other_size }) => match (size, other_size) { (IconInfo::SVG { size }, IconInfo::SVG { size: other_size }) => {
match (size, other_size) {
(Some(_), None) => Ordering::Less, (Some(_), None) => Ordering::Less,
(None, Some(_)) => Ordering::Greater, (None, Some(_)) => Ordering::Greater,
(Some(size), Some(other_size)) => size.cmp(other_size), (Some(size), Some(other_size)) => size.cmp(other_size),
(None, None) => Ordering::Equal, (None, None) => Ordering::Equal,
}, }
}
(IconInfo::SVG { .. }, _) => Ordering::Less, (IconInfo::SVG { .. }, _) => Ordering::Less,
(_, IconInfo::SVG { .. }) => Ordering::Greater, (_, IconInfo::SVG { .. }) => Ordering::Greater,

View file

@ -4,8 +4,7 @@ use lol_html::{element, HtmlRewriter, Settings};
use std::{cell::RefCell, error::Error}; use std::{cell::RefCell, error::Error};
fn parse_size<S: ToString>(size: S) -> Option<u32> { fn parse_size<S: ToString>(size: S) -> Option<u32> {
size size.to_string()
.to_string()
.parse::<f64>() .parse::<f64>()
.ok() .ok()
.map(|size| size.round() as u32) .map(|size| size.round() as u32)
@ -27,14 +26,17 @@ pub async fn get_svg_size<R: AsyncRead + Unpin>(
let width = el.get_attribute("width").and_then(parse_size); let width = el.get_attribute("width").and_then(parse_size);
let height = el.get_attribute("height").and_then(parse_size); let height = el.get_attribute("height").and_then(parse_size);
*size.borrow_mut() = Some(if let (Some(width), Some(height)) = (width, height) { *size.borrow_mut() =
Some(if let (Some(width), Some(height)) = (width, height) {
Some(IconSize::new(width, height)) Some(IconSize::new(width, height))
} else if let Some(viewbox) = viewbox { } else if let Some(viewbox) = viewbox {
regex!(r"^-?\d+\s+-?\d+\s+(\d+\.?[\d]?)\s+(\d+\.?[\d]?)") regex!(r"^-?\d+\s+-?\d+\s+(\d+\.?[\d]?)\s+(\d+\.?[\d]?)")
.captures(&viewbox) .captures(&viewbox)
.map(|captures| { .map(|captures| {
let width = parse_size(captures.get(1).unwrap().as_str()).unwrap(); let width =
let height = parse_size(captures.get(2).unwrap().as_str()).unwrap(); parse_size(captures.get(1).unwrap().as_str()).unwrap();
let height =
parse_size(captures.get(2).unwrap().as_str()).unwrap();
IconSize::new(width, height) IconSize::new(width, height)
}) })
} else { } else {

View file

@ -61,8 +61,7 @@ impl Hash for Icon {
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
( (
&self.url, &self.url,
self self.headers
.headers
.iter() .iter()
.sorted_by_key(|(key, _)| *key) .sorted_by_key(|(key, _)| *key)
.collect::<Vec<_>>(), .collect::<Vec<_>>(),

View file

@ -82,8 +82,7 @@ impl SiteIcons {
None None
} else { } else {
let body = res.bytes_stream().map(|res| { let body = res.bytes_stream().map(|res| {
res res.map(|bytes| bytes.to_vec())
.map(|bytes| bytes.to_vec())
.map_err(|err| err.to_string()) .map_err(|err| err.to_string())
}); });
@ -118,7 +117,8 @@ impl SiteIcons {
LoadedKind::SiteLogo(match html_response { LoadedKind::SiteLogo(match html_response {
Some((url, complete, body)) => { Some((url, complete, body)) => {
let (icons, _) = join!( let (icons, _) = join!(
html_parser::parse_site_logo(&url, body, |url| self.is_blacklisted(url)), html_parser::parse_site_logo(&url, body, |url| self
.is_blacklisted(url)),
complete complete
); );
@ -129,7 +129,8 @@ impl SiteIcons {
} }
.boxed_local(), .boxed_local(),
async { async {
let manifests = join_all(manifest_urls.map(|url| SiteIcons::load_manifest(url))).await; let manifests =
join_all(manifest_urls.map(|url| SiteIcons::load_manifest(url))).await;
LoadedKind::DefaultManifest( LoadedKind::DefaultManifest(
manifests manifests
@ -139,8 +140,9 @@ impl SiteIcons {
} }
.boxed_local(), .boxed_local(),
async { async {
let favicons = let favicons = join_all(
join_all(favicon_urls.map(|url| Icon::load(url.clone(), IconKind::SiteFavicon, None))) favicon_urls.map(|url| Icon::load(url.clone(), IconKind::SiteFavicon, None)),
)
.await; .await;
LoadedKind::DefaultFavicon(favicons.into_iter().find_map(|favicon| favicon.ok())) LoadedKind::DefaultFavicon(favicons.into_iter().find_map(|favicon| favicon.ok()))

View file

@ -40,8 +40,7 @@ async fn load_manifest_cached(url: Url) -> Result<Vec<Icon>, String> {
.await .await
.map_err(|e| format!("{}: {:?}", url, e))?; .map_err(|e| format!("{}: {:?}", url, e))?;
Ok( Ok(join_all(manifest.icons.into_iter().map(|icon| async move {
join_all(manifest.icons.into_iter().map(|icon| async move {
if let Ok(src) = url.join(&icon.src) { if let Ok(src) = url.join(&icon.src) {
Icon::load(src, IconKind::AppIcon, icon.sizes).await.ok() Icon::load(src, IconKind::AppIcon, icon.sizes).await.ok()
} else { } else {
@ -51,6 +50,5 @@ async fn load_manifest_cached(url: Url) -> Result<Vec<Icon>, String> {
.await .await
.into_iter() .into_iter()
.filter_map(|icon| icon) .filter_map(|icon| icon)
.collect(), .collect())
)
} }