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

Remove superfluous ref keyword #361

Merged
merged 5 commits into from
Dec 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
pull_request:
branches: [master]
branches: [main]

jobs:
build:
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,8 @@ fn main() -> std::io::Result<()> {

// Set all bookmarks to the PDF Object tree then set the Outlines to the Bookmark content map.
if let Some(n) = document.build_outline() {
if let Ok(x) = document.get_object_mut(catalog_object.0) {
if let Object::Dictionary(ref mut dict) = x {
dict.set("Outlines", Object::Reference(n));
}
if let Ok(Object::Dictionary(dict)) = document.get_object_mut(catalog_object.0) {
dict.set("Outlines", Object::Reference(n));
}
}

Expand Down
46 changes: 23 additions & 23 deletions examples/extract_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ use shellexpand;
#[cfg(feature = "async")]
use tokio::runtime::Builder;

static IGNORE: &[&str] = &[
"Length",
"BBox",
"FormType",
"Matrix",
"Type",
"XObject",
"Subtype",
"Filter",
"ColorSpace",
"Width",
"Height",
"BitsPerComponent",
"Length1",
"Length2",
"Length3",
"PTEX.FileName",
"PTEX.PageNumber",
"PTEX.InfoDict",
"FontDescriptor",
"ExtGState",
"MediaBox",
"Annot",
static IGNORE: &[&[u8]] = &[
b"Length",
b"BBox",
b"FormType",
b"Matrix",
b"Type",
b"XObject",
b"Subtype",
b"Filter",
b"ColorSpace",
b"Width",
b"Height",
b"BitsPerComponent",
b"Length1",
b"Length2",
b"Length3",
b"PTEX.FileName",
b"PTEX.PageNumber",
b"PTEX.InfoDict",
b"FontDescriptor",
b"ExtGState",
b"MediaBox",
b"Annot",
];

#[derive(Debug, Deserialize, Serialize)]
Expand Down
50 changes: 25 additions & 25 deletions examples/extract_toc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ use shellexpand;
#[cfg(feature = "async")]
use tokio::runtime::Builder;

static IGNORE: &[&str] = &[
"Length",
"BBox",
"FormType",
"Matrix",
"Resources",
"Type",
"XObject",
"Subtype",
"Filter",
"ColorSpace",
"Width",
"Height",
"BitsPerComponent",
"Length1",
"Length2",
"Length3",
"PTEX.FileName",
"PTEX.PageNumber",
"PTEX.InfoDict",
"FontDescriptor",
"ExtGState",
"Font",
"MediaBox",
"Annot",
static IGNORE: &[&[u8]] = &[
b"Length",
b"BBox",
b"FormType",
b"Matrix",
b"Resources",
b"Type",
b"XObject",
b"Subtype",
b"Filter",
b"ColorSpace",
b"Width",
b"Height",
b"BitsPerComponent",
b"Length1",
b"Length2",
b"Length3",
b"PTEX.FileName",
b"PTEX.PageNumber",
b"PTEX.InfoDict",
b"FontDescriptor",
b"ExtGState",
b"Font",
b"MediaBox",
b"Annot",
];

#[derive(Parser, Debug)]
Expand Down
14 changes: 5 additions & 9 deletions examples/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ fn main() {
let pages = doc.get_pages();

// This is actually better than extend as we use less allocations and cloning then.
pages
.into_iter()
.map(|(_, object_id)| {
pages.into_values().map(|object_id| {
// We use this as the return object for Bookmarking to deturmine what it points too.
// We only want to do this for the first page though.
if first_object.is_none() {
Expand Down Expand Up @@ -250,9 +248,7 @@ fn main() {
// Set new "Kids" list (collected from documents pages) for "Pages"
dictionary.set(
"Kids",
documents_pages
.into_iter()
.map(|(object_id, _)| Object::Reference(object_id))
documents_pages.into_keys().map(|object_id| Object::Reference(object_id))
.collect::<Vec<_>>(),
);

Expand Down Expand Up @@ -281,9 +277,9 @@ fn main() {
document.adjust_zero_pages();

//Set all bookmarks to the PDF Object tree then set the Outlines to the Bookmark content map.
if let Some(n) = document.build_outline() {
if let Ok(Object::Dictionary(ref mut dict)) = document.get_object_mut(catalog_id) {
dict.set("Outlines", Object::Reference(n));
if let Some(outline_id) = document.build_outline() {
if let Ok(Object::Dictionary(dict)) = document.get_object_mut(catalog_id) {
dict.set("Outlines", Object::Reference(outline_id));
}
}

Expand Down
8 changes: 4 additions & 4 deletions pdfutil/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ fn main() {
document.adjust_zero_pages();

//Set all bookmarks to the PDF Object tree then set the Outlines to the Bookmark content map.
if let Some(n) = document.build_outline() {
if let Ok(Object::Dictionary(ref mut dict)) = document.get_object_mut(catalog_id) {
dict.set("Outlines", Object::Reference(n));
if let Some(outline_id) = document.build_outline() {
if let Ok(Object::Dictionary(dict)) = document.get_object_mut(catalog_id) {
dict.set("Outlines", Object::Reference(outline_id));
}
}

Expand Down Expand Up @@ -407,7 +407,7 @@ fn main() {
}
"print_streams" => {
for (_, object) in doc.objects.iter() {
if let Object::Stream(ref stream) = *object {
if let Object::Stream(stream) = object {
info!("{:?}", stream.dict);
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ impl Document {
}
fn traverse_object<A: Fn(&mut Object)>(object: &mut Object, action: &A, refs: &mut Vec<ObjectId>) {
action(object);
match *object {
Object::Array(ref mut array) => traverse_array(array, action, refs),
Object::Dictionary(ref mut dict) => traverse_dictionary(dict, action, refs),
Object::Stream(ref mut stream) => traverse_dictionary(&mut stream.dict, action, refs),
match object {
Object::Array(array) => traverse_array(array, action, refs),
Object::Dictionary(dict) => traverse_dictionary(dict, action, refs),
Object::Stream(stream) => traverse_dictionary(&mut stream.dict, action, refs),
Object::Reference(id) => {
if !refs.contains(&id) {
refs.push(id);
if !refs.contains(id) {
refs.push(*id);
}
}
_ => {}
Expand Down Expand Up @@ -302,7 +302,7 @@ impl Document {
// Only strings and streams are encrypted
match obj {
Object::Stream(stream) => stream.set_content(decrypted),
Object::String(ref mut content, _) => *content = decrypted,
Object::String(content, _) => *content = decrypted,
_ => {}
}
}
Expand Down Expand Up @@ -455,15 +455,15 @@ impl Document {
) {
if let Ok(font) = resources.get(b"Font") {
let font_dict = match font {
Object::Reference(ref id) => doc.get_object(*id).and_then(Object::as_dict).ok(),
Object::Dictionary(ref dict) => Some(dict),
Object::Reference(id) => doc.get_object(*id).and_then(Object::as_dict).ok(),
Object::Dictionary(dict) => Some(dict),
_ => None,
};
if let Some(font_dict) = font_dict {
for (name, value) in font_dict.iter() {
let font = match *value {
Object::Reference(id) => doc.get_dictionary(id).ok(),
Object::Dictionary(ref dict) => Some(dict),
let font = match value {
Object::Reference(id) => doc.get_dictionary(*id).ok(),
Object::Dictionary(dict) => Some(dict),
_ => None,
};
if !fonts.contains_key(name) {
Expand Down Expand Up @@ -494,14 +494,14 @@ impl Document {
let mut annotations = vec![];
if let Ok(page) = self.get_dictionary(page_id) {
match page.get(b"Annots") {
Ok(Object::Reference(ref id)) => self
Ok(Object::Reference(id)) => self
.get_object(*id)
.and_then(Object::as_array)?
.iter()
.flat_map(Object::as_reference)
.flat_map(|id| self.get_dictionary(id))
.for_each(|a| annotations.push(a)),
Ok(Object::Array(ref a)) => a
Ok(Object::Array(a)) => a
.iter()
.flat_map(Object::as_reference)
.flat_map(|id| self.get_dictionary(id))
Expand Down
4 changes: 2 additions & 2 deletions src/encodings/cmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ impl ToUnicodeCMap {
let bf_ranges_map = &self.bf_ranges[(code_len - 1) as usize];

bf_ranges_map.get_key_value(&code).map(|(range, value)| match value {
HexString(ref vec) => {
HexString(vec) => {
let mut ret_vec = vec.clone();
*(ret_vec.last_mut().unwrap()) += (code - range.start()) as u16;
ret_vec
}
UTF16CodePoint { offset } => vec![u32::wrapping_add(code, *offset) as u16],
ArrayOfHexStrings(ref vec_of_strings) => vec_of_strings[(code - range.start()) as usize].clone(),
ArrayOfHexStrings(vec_of_strings) => vec_of_strings[(code - range.start()) as usize].clone(),
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/encodings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum Encoding<'a> {
UnicodeMapEncoding(ToUnicodeCMap),
}

impl<'a> std::fmt::Debug for Encoding<'a> {
impl std::fmt::Debug for Encoding<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
// UnicodeCMap and Bytes encoding ommitted to not bloat debug log
Expand All @@ -42,7 +42,7 @@ impl<'a> std::fmt::Debug for Encoding<'a> {
}
}

impl<'a> Encoding<'a> {
impl Encoding<'_> {
pub fn bytes_to_string(&self, bytes: &[u8]) -> Result<String> {
match self {
Self::OneByteEncoding(map) => Ok(bytes_to_string(map, bytes)),
Expand Down
36 changes: 18 additions & 18 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ impl Object {
}

pub fn as_bool(&self) -> Result<bool> {
match *self {
Object::Boolean(ref value) => Ok(*value),
match self {
Object::Boolean(value) => Ok(*value),
_ => Err(Error::ObjectType {
expected: "Boolean",
found: self.enum_variant(),
Expand All @@ -152,8 +152,8 @@ impl Object {
}

pub fn as_i64(&self) -> Result<i64> {
match *self {
Object::Integer(ref value) => Ok(*value),
match self {
Object::Integer(value) => Ok(*value),
_ => Err(Error::ObjectType {
expected: "Integer",
found: self.enum_variant(),
Expand Down Expand Up @@ -185,8 +185,8 @@ impl Object {
}

pub fn as_name(&self) -> Result<&[u8]> {
match *self {
Object::Name(ref name) => Ok(name),
match self {
Object::Name(name) => Ok(name),
_ => Err(Error::ObjectType {
expected: "Name",
found: self.enum_variant(),
Expand Down Expand Up @@ -215,8 +215,8 @@ impl Object {
}

pub fn as_reference(&self) -> Result<ObjectId> {
match *self {
Object::Reference(ref id) => Ok(*id),
match self {
Object::Reference(id) => Ok(*id),
_ => Err(Error::ObjectType {
expected: "Reference",
found: self.enum_variant(),
Expand All @@ -225,8 +225,8 @@ impl Object {
}

pub fn as_array(&self) -> Result<&Vec<Object>> {
match *self {
Object::Array(ref arr) => Ok(arr),
match self {
Object::Array(arr) => Ok(arr),
_ => Err(Error::ObjectType {
expected: "Array",
found: self.enum_variant(),
Expand All @@ -235,8 +235,8 @@ impl Object {
}

pub fn as_array_mut(&mut self) -> Result<&mut Vec<Object>> {
match *self {
Object::Array(ref mut arr) => Ok(arr),
match self {
Object::Array(arr) => Ok(arr),
_ => Err(Error::ObjectType {
expected: "Array",
found: self.enum_variant(),
Expand All @@ -245,8 +245,8 @@ impl Object {
}

pub fn as_dict(&self) -> Result<&Dictionary> {
match *self {
Object::Dictionary(ref dict) => Ok(dict),
match self {
Object::Dictionary(dict) => Ok(dict),
_ => Err(Error::ObjectType {
expected: "Dictionary",
found: self.enum_variant(),
Expand All @@ -255,8 +255,8 @@ impl Object {
}

pub fn as_dict_mut(&mut self) -> Result<&mut Dictionary> {
match *self {
Object::Dictionary(ref mut dict) => Ok(dict),
match self {
Object::Dictionary(dict) => Ok(dict),
_ => Err(Error::ObjectType {
expected: "Dictionary",
found: self.enum_variant(),
Expand All @@ -265,8 +265,8 @@ impl Object {
}

pub fn as_stream(&self) -> Result<&Stream> {
match *self {
Object::Stream(ref stream) => Ok(stream),
match self {
Object::Stream(stream) => Ok(stream),
_ => Err(Error::ObjectType {
expected: "Stream",
found: self.enum_variant(),
Expand Down
Loading
Loading