diff --git a/src/family.rs b/src/family.rs index 90c6eae..28c93b3 100644 --- a/src/family.rs +++ b/src/family.rs @@ -40,7 +40,7 @@ impl<'a> Family<'a> { } } -pub fn group_by_family_sort_by_name(faces: &Vec) -> Vec> { +pub fn group_by_family_sort_by_name(faces: &[FaceInfo]) -> Vec> { let mut families = HashMap::new(); faces.iter().for_each(|face| { @@ -56,5 +56,5 @@ pub fn group_by_family_sort_by_name(faces: &Vec) -> Vec> { family.faces.sort_unstable_by(|a, b| a.name.cmp(&b.name)) } - return families; + families } diff --git a/src/loader/mod.rs b/src/loader/mod.rs index 2b76f12..0ae2793 100644 --- a/src/loader/mod.rs +++ b/src/loader/mod.rs @@ -43,7 +43,7 @@ pub fn faces_contains(c: char) -> Vec { } } - return face.transpose(); + face.transpose() }) .filter_map(|f| f.ok()) .collect() diff --git a/src/preview/browser/builder.rs b/src/preview/browser/builder.rs index 0c3c755..380c192 100644 --- a/src/preview/browser/builder.rs +++ b/src/preview/browser/builder.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::iter::FromIterator; +use std::{fmt::Write, iter::FromIterator}; use super::SingleThreadServer; use crate::family::Family; @@ -43,21 +43,23 @@ impl<'a> Builder<'a> { } fn build_html(self, c: char) -> String { + let font_previews = + self.families.into_iter().fold(String::new(), |mut acc: String, family| { + write!( + &mut acc, + include_str!("statics/preview_block_template.html"), + char = c, + family = family, + ) + .expect("write to string should always success"); + acc + }); + format!( include_str!("statics/template.html"), style = include_str!("statics/style.css"), script = include_str!("statics/script.js"), - font_previews = self - .families - .into_iter() - .map(|family| { - format!( - include_str!("statics/preview_block_template.html"), - char = c, - family = family - ) - }) - .collect::() + font_previews = font_previews, ) } diff --git a/src/preview/terminal/ui/mod.rs b/src/preview/terminal/ui/mod.rs index 41b2d9d..dcd5112 100644 --- a/src/preview/terminal/ui/mod.rs +++ b/src/preview/terminal/ui/mod.rs @@ -59,7 +59,7 @@ pub struct UI<'a> { impl<'a: 'a> UI<'a> { pub fn new(c: char, families: Vec>) -> Option { - if families.len() > 0 { + if !families.is_empty() { Some(Self { state: State::new(c, families), idle_redraw: 0 }) } else { None diff --git a/src/rasterizer/bitmap.rs b/src/rasterizer/bitmap.rs index 44d35ec..58ceca9 100644 --- a/src/rasterizer/bitmap.rs +++ b/src/rasterizer/bitmap.rs @@ -25,6 +25,7 @@ pub struct Metrics { pub width: usize, } +#[allow(dead_code)] // TODO: remove this pub struct Bitmap { pixel_mode: u8, pitch: u32, @@ -33,7 +34,8 @@ pub struct Bitmap { } impl Bitmap { - pub(super) fn new(_font_face: FontFace) -> Self { + #[allow(dead_code)] // remove this + pub fn new(_font_face: FontFace) -> Self { // let face_rec = unsafe { &*font_face.face }; // let glyph = unsafe { &*face_rec.glyph }; // let left = glyph.bitmap_left; diff --git a/src/rasterizer/font_face.rs b/src/rasterizer/font_face.rs index 0d898ac..1db36bf 100644 --- a/src/rasterizer/font_face.rs +++ b/src/rasterizer/font_face.rs @@ -19,6 +19,7 @@ use crate::rasterizer::bitmap::Bitmap; pub struct FontFace { + #[allow(dead_code)] // TODO: remove this face: owned_ttf_parser::OwnedFace, height: u32, width: u32,