Skip to content

Commit 89b7410

Browse files
committed
Fix clippy lints
1 parent 77b0c6e commit 89b7410

6 files changed

Lines changed: 55 additions & 39 deletions

File tree

examples/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn main() -> std::io::Result<()> {
8787

8888
// Add SMask if the image has transparency.
8989
if let Some(encoded) = &mask {
90-
let mut s_mask = writer.image_xobject(s_mask_id, &encoded);
90+
let mut s_mask = writer.image_xobject(s_mask_id, encoded);
9191
s_mask.filter(filter);
9292
s_mask.width(dynamic.width() as i32);
9393
s_mask.height(dynamic.height() as i32);

src/color.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl ColorSpace<'_> {
283283
Some([1.8, 1.8, 1.8]),
284284
Some([
285285
0.7976749, 0.2880402, 0.0, 0.1351917, 0.7118741, 0.0, 0.0313534,
286-
0.0000857, 0.8252100,
286+
0.0000857, 0.82521,
287287
]),
288288
)
289289
}
@@ -296,7 +296,7 @@ impl ColorSpace<'_> {
296296
Some([1.8, 1.8, 1.8]),
297297
Some([
298298
0.6502043, 0.3202499, 0.0, 0.1780774, 0.6020711, 0.0678390, 0.1359384,
299-
0.0776791, 0.7573710,
299+
0.0776791, 0.757371,
300300
]),
301301
)
302302
}
@@ -308,7 +308,7 @@ impl ColorSpace<'_> {
308308
None,
309309
Some([2.2, 2.2, 2.2]),
310310
Some([
311-
0.6068909, 0.2989164, 0.0, 0.1735011, 0.5865990, 0.0660957, 0.2003480,
311+
0.6068909, 0.2989164, 0.0, 0.1735011, 0.586599, 0.0660957, 0.200348,
312312
0.1144845, 1.1162243,
313313
]),
314314
)
@@ -321,7 +321,7 @@ impl ColorSpace<'_> {
321321
None,
322322
Some([2.2, 2.2, 2.2]),
323323
Some([
324-
0.4306190, 0.2220379, 0.0201853, 0.3415419, 0.7066384, 0.1295504,
324+
0.430619, 0.2220379, 0.0201853, 0.3415419, 0.7066384, 0.1295504,
325325
0.1783091, 0.0713236, 0.9390944,
326326
]),
327327
)

src/content.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Content {
99
impl Content {
1010
/// Create a new content stream with the default buffer capacity
1111
/// (currently 1 KB).
12+
#[allow(clippy::new_without_default)]
1213
pub fn new() -> Self {
1314
Self::with_capacity(1024)
1415
}

src/files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a> FileSpec<'a> {
6363

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

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

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

99-
/// Writer for a _embedded file parameter dictionary_.
99+
/// Writer for an _embedded file parameter dictionary_.
100100
///
101101
/// This struct is created by [`EmbeddedFile::params`].
102102
pub struct EmbeddingParams<'a> {

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ to the [PDF specification] to make sure you create valid PDFs.
8181

8282
#![forbid(unsafe_code)]
8383
#![deny(missing_docs)]
84+
#![allow(clippy::wrong_self_convention)]
8485

8586
#[macro_use]
8687
mod macros;
@@ -187,6 +188,7 @@ pub struct PdfWriter {
187188
impl PdfWriter {
188189
/// Create a new PDF writer with the default buffer capacity
189190
/// (currently 8 KB).
191+
#[allow(clippy::new_without_default)]
190192
pub fn new() -> Self {
191193
Self::with_capacity(8 * 1024)
192194
}
@@ -220,6 +222,7 @@ impl PdfWriter {
220222

221223
/// The number of bytes that were written so far.
222224
#[inline]
225+
#[allow(clippy::len_without_is_empty)]
223226
pub fn len(&self) -> usize {
224227
self.buf.len()
225228
}
@@ -249,7 +252,8 @@ impl PdfWriter {
249252
}
250253

251254
// Fill in free list.
252-
for free_id in written..object_id.get() {
255+
let start = written;
256+
for free_id in start..object_id.get() {
253257
let mut next = free_id + 1;
254258
if next == object_id.get() {
255259
// Find next free id.

src/object.rs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -321,37 +321,24 @@ impl Date {
321321

322322
impl Primitive for Date {
323323
fn write(self, buf: &mut Vec<u8>) {
324-
write!(buf, "(D:{:04}", self.year).unwrap();
325-
326-
self.month
327-
.and_then(|month| {
328-
write!(buf, "{:02}", month).unwrap();
329-
self.day
330-
})
331-
.and_then(|day| {
332-
write!(buf, "{:02}", day).unwrap();
333-
self.hour
334-
})
335-
.and_then(|hour| {
336-
write!(buf, "{:02}", hour).unwrap();
337-
self.minute
338-
})
339-
.and_then(|minute| {
340-
write!(buf, "{:02}", minute).unwrap();
341-
self.second
342-
})
343-
.and_then(|second| {
344-
write!(buf, "{:02}", second).unwrap();
345-
self.utc_offset_hour
346-
})
347-
.map(|utc_offset_hour| {
348-
if utc_offset_hour == 0 && self.utc_offset_minute == 0 {
349-
buf.push(b'Z');
350-
} else {
351-
write!(buf, "{:+03}'{:02}", utc_offset_hour, self.utc_offset_minute)
352-
.unwrap();
353-
}
354-
});
324+
buf.extend(b"(D:");
325+
326+
(|| {
327+
write!(buf, "{:04}", self.year).unwrap();
328+
write!(buf, "{:02}", self.month?).unwrap();
329+
write!(buf, "{:02}", self.day?).unwrap();
330+
write!(buf, "{:02}", self.hour?).unwrap();
331+
write!(buf, "{:02}", self.minute?).unwrap();
332+
write!(buf, "{:02}", self.second?).unwrap();
333+
let utc_offset_hour = self.utc_offset_hour?;
334+
if utc_offset_hour == 0 && self.utc_offset_minute == 0 {
335+
buf.push(b'Z');
336+
} else {
337+
write!(buf, "{:+03}'{:02}", utc_offset_hour, self.utc_offset_minute)
338+
.unwrap();
339+
}
340+
Some(())
341+
})();
355342

356343
buf.push(b')');
357344
}
@@ -463,6 +450,12 @@ impl<'a> Array<'a> {
463450
self.len
464451
}
465452

453+
/// Whether no items have been written so far.
454+
#[inline]
455+
pub fn is_empty(&self) -> bool {
456+
self.len == 0
457+
}
458+
466459
/// Start writing an arbitrary item.
467460
#[inline]
468461
pub fn push(&mut self) -> Obj<'_> {
@@ -543,6 +536,12 @@ where
543536
self.array.len()
544537
}
545538

539+
/// Whether no items have been written so far.
540+
#[inline]
541+
pub fn is_empty(&self) -> bool {
542+
self.len() == 0
543+
}
544+
546545
/// Write an item.
547546
#[inline]
548547
pub fn item(&mut self, value: T) -> &mut Self
@@ -600,6 +599,12 @@ impl<'a> Dict<'a> {
600599
self.len
601600
}
602601

602+
/// Whether no pairs have been written so far.
603+
#[inline]
604+
pub fn is_empty(&self) -> bool {
605+
self.len == 0
606+
}
607+
603608
/// Start writing a pair with an arbitrary value.
604609
#[inline]
605610
pub fn insert(&mut self, key: Name) -> Obj<'_> {
@@ -691,6 +696,12 @@ where
691696
self.dict.len()
692697
}
693698

699+
/// Whether no pairs have been written so far.
700+
#[inline]
701+
pub fn is_empty(&self) -> bool {
702+
self.len() == 0
703+
}
704+
694705
/// Write a key-value pair.
695706
#[inline]
696707
pub fn pair(&mut self, key: Name, value: T) -> &mut Self

0 commit comments

Comments
 (0)