Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
laurmaedje committed Aug 3, 2023
1 parent 77b0c6e commit 89b7410
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn main() -> std::io::Result<()> {

// Add SMask if the image has transparency.
if let Some(encoded) = &mask {
let mut s_mask = writer.image_xobject(s_mask_id, &encoded);
let mut s_mask = writer.image_xobject(s_mask_id, encoded);
s_mask.filter(filter);
s_mask.width(dynamic.width() as i32);
s_mask.height(dynamic.height() as i32);
Expand Down
8 changes: 4 additions & 4 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl ColorSpace<'_> {
Some([1.8, 1.8, 1.8]),
Some([
0.7976749, 0.2880402, 0.0, 0.1351917, 0.7118741, 0.0, 0.0313534,
0.0000857, 0.8252100,
0.0000857, 0.82521,
]),
)
}
Expand All @@ -296,7 +296,7 @@ impl ColorSpace<'_> {
Some([1.8, 1.8, 1.8]),
Some([
0.6502043, 0.3202499, 0.0, 0.1780774, 0.6020711, 0.0678390, 0.1359384,
0.0776791, 0.7573710,
0.0776791, 0.757371,
]),
)
}
Expand All @@ -308,7 +308,7 @@ impl ColorSpace<'_> {
None,
Some([2.2, 2.2, 2.2]),
Some([
0.6068909, 0.2989164, 0.0, 0.1735011, 0.5865990, 0.0660957, 0.2003480,
0.6068909, 0.2989164, 0.0, 0.1735011, 0.586599, 0.0660957, 0.200348,
0.1144845, 1.1162243,
]),
)
Expand All @@ -321,7 +321,7 @@ impl ColorSpace<'_> {
None,
Some([2.2, 2.2, 2.2]),
Some([
0.4306190, 0.2220379, 0.0201853, 0.3415419, 0.7066384, 0.1295504,
0.430619, 0.2220379, 0.0201853, 0.3415419, 0.7066384, 0.1295504,
0.1783091, 0.0713236, 0.9390944,
]),
)
Expand Down
1 change: 1 addition & 0 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Content {
impl Content {
/// Create a new content stream with the default buffer capacity
/// (currently 1 KB).
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self::with_capacity(1024)
}
Expand Down
4 changes: 2 additions & 2 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'a> FileSpec<'a> {

deref!('a, FileSpec<'a> => Dict<'a>, dict);

/// Writer for a _embedded file stream_.
/// Writer for an _embedded file stream_.
///
/// This struct is created by [`PdfWriter::embedded_file`].
pub struct EmbeddedFile<'a> {
Expand Down Expand Up @@ -96,7 +96,7 @@ impl<'a> EmbeddedFile<'a> {

deref!('a, EmbeddedFile<'a> => Stream<'a>, stream);

/// Writer for a _embedded file parameter dictionary_.
/// Writer for an _embedded file parameter dictionary_.
///
/// This struct is created by [`EmbeddedFile::params`].
pub struct EmbeddingParams<'a> {
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ to the [PDF specification] to make sure you create valid PDFs.

#![forbid(unsafe_code)]
#![deny(missing_docs)]
#![allow(clippy::wrong_self_convention)]

#[macro_use]
mod macros;
Expand Down Expand Up @@ -187,6 +188,7 @@ pub struct PdfWriter {
impl PdfWriter {
/// Create a new PDF writer with the default buffer capacity
/// (currently 8 KB).
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self::with_capacity(8 * 1024)
}
Expand Down Expand Up @@ -220,6 +222,7 @@ impl PdfWriter {

/// The number of bytes that were written so far.
#[inline]
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.buf.len()
}
Expand Down Expand Up @@ -249,7 +252,8 @@ impl PdfWriter {
}

// Fill in free list.
for free_id in written..object_id.get() {
let start = written;
for free_id in start..object_id.get() {
let mut next = free_id + 1;
if next == object_id.get() {
// Find next free id.
Expand Down
73 changes: 42 additions & 31 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,37 +321,24 @@ impl Date {

impl Primitive for Date {
fn write(self, buf: &mut Vec<u8>) {
write!(buf, "(D:{:04}", self.year).unwrap();

self.month
.and_then(|month| {
write!(buf, "{:02}", month).unwrap();
self.day
})
.and_then(|day| {
write!(buf, "{:02}", day).unwrap();
self.hour
})
.and_then(|hour| {
write!(buf, "{:02}", hour).unwrap();
self.minute
})
.and_then(|minute| {
write!(buf, "{:02}", minute).unwrap();
self.second
})
.and_then(|second| {
write!(buf, "{:02}", second).unwrap();
self.utc_offset_hour
})
.map(|utc_offset_hour| {
if utc_offset_hour == 0 && self.utc_offset_minute == 0 {
buf.push(b'Z');
} else {
write!(buf, "{:+03}'{:02}", utc_offset_hour, self.utc_offset_minute)
.unwrap();
}
});
buf.extend(b"(D:");

(|| {
write!(buf, "{:04}", self.year).unwrap();
write!(buf, "{:02}", self.month?).unwrap();
write!(buf, "{:02}", self.day?).unwrap();
write!(buf, "{:02}", self.hour?).unwrap();
write!(buf, "{:02}", self.minute?).unwrap();
write!(buf, "{:02}", self.second?).unwrap();
let utc_offset_hour = self.utc_offset_hour?;
if utc_offset_hour == 0 && self.utc_offset_minute == 0 {
buf.push(b'Z');
} else {
write!(buf, "{:+03}'{:02}", utc_offset_hour, self.utc_offset_minute)
.unwrap();
}
Some(())
})();

buf.push(b')');
}
Expand Down Expand Up @@ -463,6 +450,12 @@ impl<'a> Array<'a> {
self.len
}

/// Whether no items have been written so far.
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}

/// Start writing an arbitrary item.
#[inline]
pub fn push(&mut self) -> Obj<'_> {
Expand Down Expand Up @@ -543,6 +536,12 @@ where
self.array.len()
}

/// Whether no items have been written so far.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Write an item.
#[inline]
pub fn item(&mut self, value: T) -> &mut Self
Expand Down Expand Up @@ -600,6 +599,12 @@ impl<'a> Dict<'a> {
self.len
}

/// Whether no pairs have been written so far.
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}

/// Start writing a pair with an arbitrary value.
#[inline]
pub fn insert(&mut self, key: Name) -> Obj<'_> {
Expand Down Expand Up @@ -691,6 +696,12 @@ where
self.dict.len()
}

/// Whether no pairs have been written so far.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Write a key-value pair.
#[inline]
pub fn pair(&mut self, key: Name, value: T) -> &mut Self
Expand Down

0 comments on commit 89b7410

Please sign in to comment.