Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply clippy suggestions #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
598 changes: 300 additions & 298 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/atomizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'src> Atomizer<'src> {
pub fn new(parser: Parser<'src>) -> Self {
Atomizer {
state: AtomizerState::Parsing,
parser: parser,
parser,
current_style: Style::default(),
is_code: false,
is_alt_text: false,
Expand Down
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,13 @@ pub fn markdown_to_pdf(markdown: &str, cfg: &Config) -> Result<PdfDocumentRefere

{
let mut resources = resources::Resources::new(cfg.clone());
let atomizer = atomizer::Atomizer::new(Parser::new(&markdown));
let atomizer = atomizer::Atomizer::new(Parser::new(markdown));

let atoms: Vec<atomizer::Event> = atomizer.collect();
let mut loader = resources::SimpleLoader::new(PathBuf::from(&cfg.resources_directory));
for event in atoms.iter() {
match event {
atomizer::Event::Atom(atomizer::Atom::Image { uri }) => {
loader.queue_image(uri);
}

_ => {}
if let atomizer::Event::Atom(atomizer::Atom::Image { uri }) = event {
loader.queue_image(uri);
}
}

Expand Down Expand Up @@ -200,7 +196,7 @@ pub fn markdown_to_pdf(markdown: &str, cfg: &Config) -> Result<PdfDocumentRefere
&regular
};

let font_scale = util::scale_from_style(&cfg, &style);
let font_scale = util::scale_from_style(cfg, &style);

current_layer.set_font(font, font_scale.y as i64);
current_layer.write_text(text, font);
Expand Down
6 changes: 3 additions & 3 deletions src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct Pages<'res> {
impl<'res> Pages<'res> {
pub fn new(cfg: &'res Config, resources: &'res Resources) -> Self {
Self {
cfg: cfg,
resources: resources,
cfg,
resources,
pages: vec![],
current_page: Page::new(),
current_y: cfg.page_size.1 - cfg.margin.1,
Expand All @@ -44,7 +44,7 @@ impl<'res> Pages<'res> {
match section {
Section::Plain(spans) => {
self.current_page
.render_spans(self.resources, &spans, start_x, self.current_y)
.render_spans(self.resources, spans, start_x, self.current_y)
}
Section::VerticalSpace(_) => {}
Section::ThematicBreak => {
Expand Down
8 changes: 4 additions & 4 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Resources {
root_path: config.resources_directory.clone(),
images: BTreeMap::new(),
fonts: BTreeMap::new(),
config: config,
config,
};
res.fonts.insert(
DEFAULT_REGULAR_FONT.into(),
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Resources {
impl SimpleLoader {
pub fn new(root_path: PathBuf) -> Self {
Self {
root_path: root_path,
root_path,
queued_images: HashSet::new(),
queued_fonts: HashSet::new(),
}
Expand All @@ -110,7 +110,7 @@ impl SimpleLoader {
let filename = self.root_path.join(font);

let mut buffer = Vec::new();
let mut font_file = std::fs::File::open(&filename)?;
let mut font_file = std::fs::File::open(filename)?;
font_file.read_to_end(&mut buffer)?;

let font = Font::from_bytes(buffer)?;
Expand All @@ -120,7 +120,7 @@ impl SimpleLoader {
fn load_image(&self, image_path: &str) -> Result<DynamicImage, Error> {
let filename = self.root_path.join(image_path);

let image = image::open(&filename)?;
let image = image::open(filename)?;
Ok(image)
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/sectioner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ impl<'res> Sectioner<'res> {
lines: Vec::new(),
current_line: Vec::new(),
current_code_block: Vec::new(),
min_x: min_x,
max_x: max_x,
min_x,
max_x,
subsection: None,
is_code: false,
is_alt_text: false,
resources: resources,
resources,
cfg: resources.get_config(),
}
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'res> Sectioner<'res> {
self.subsection = Some(Box::new(Sectioner::new(
self.min_x + self.cfg.list_indentation,
self.max_x,
&self.resources,
self.resources,
)))
}
SizedEvent::EndBlock(BlockTag::ListItem) => return Some(SubsectionType::List),
Expand All @@ -85,7 +85,7 @@ impl<'res> Sectioner<'res> {
self.subsection = Some(Box::new(Sectioner::new(
self.min_x + self.cfg.quote_indentation,
self.max_x,
&self.resources,
self.resources,
)))
}
SizedEvent::EndBlock(BlockTag::BlockQuote) => return Some(SubsectionType::Quote),
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'res> Sectioner<'res> {
}

pub fn new_line(&mut self) {
if self.current_line.len() == 0 {
if self.current_line.is_empty() {
return;
}
if self.is_code {
Expand All @@ -182,7 +182,7 @@ impl<'res> Sectioner<'res> {

pub fn get_vec(mut self) -> Vec<Section> {
// Make sure that current_line is put into the output
if self.current_line.len() != 0 {
if !self.current_line.is_empty() {
self.lines.push(Section::plain(self.current_line));
}
// Check if the last section is a blank-type of section, so that we
Expand Down
4 changes: 2 additions & 2 deletions src/sizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ where

let sized_atom = SizedAtom {
atom: Atom::Text { text, style },
width: width,
height: height,
width,
height,
};
Some(SizedEvent::SizedAtom(sized_atom))
}
Expand Down
12 changes: 6 additions & 6 deletions src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ impl Span {

pub fn width(&self, resources: &Resources) -> Mm {
match self {
Span::Text { text, style, .. } => width_of_text(resources, &style, &text).into(),
Span::Image { width, .. } => width.clone(),
Span::Rect { width, .. } => width.clone(),
Span::Text { text, style, .. } => width_of_text(resources, style, text).into(),
Span::Image { width, .. } => *width,
Span::Rect { width, .. } => *width,
}
}

pub fn height(&self, resources: &Resources) -> Mm {
match self {
Span::Text { style, .. } => font_height(resources, &style).into(),
Span::Image { height, .. } => height.clone(),
Span::Rect { height, .. } => height.clone(),
Span::Text { style, .. } => font_height(resources, style).into(),
Span::Image { height, .. } => *height,
Span::Rect { height, .. } => *height,
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashSet;

#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Default)]
pub struct Style(HashSet<Class>);

#[derive(Debug, Hash, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -30,11 +31,7 @@ impl Style {
}
}

impl Default for Style {
fn default() -> Self {
Style(HashSet::new())
}
}


impl<'a, I: Iterator<Item = &'a Class>> From<I> for Style {
fn from(classes: I) -> Self {
Expand Down