Skip to content

Commit

Permalink
refactor: apply Rust edition 2021 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xricksanchez committed Jan 10, 2025
1 parent 18ad317 commit 7c34345
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
29 changes: 13 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ impl<'a> PdfSimpleFont<'a> {
code += 1;
}
_ => {
panic!("wrong type {:?}", o);
panic!("wrong type {o:?}");
}
}
}
Expand Down Expand Up @@ -705,7 +705,7 @@ impl<'a> PdfSimpleFont<'a> {
if w.0 != -1 {
table[w.0 as usize] = if base_name == "ZapfDingbats" {
zapfglyphnames::zapfdigbats_names_to_unicode(w.2)
.unwrap_or_else(|| panic!("bad name {:?}", w))
.unwrap_or_else(|| panic!("bad name {w:?}"))
} else {
glyphnames::name_to_unicode(w.2).unwrap()
}
Expand Down Expand Up @@ -960,7 +960,7 @@ impl PdfFont for PdfSimpleFont<'_> {
println!("falling back to encoding {char} -> {s:?}");
s
},
|s| s.clone(),
std::clone::Clone::clone,
);
return s;
}
Expand Down Expand Up @@ -1016,7 +1016,7 @@ impl PdfFont for PdfType3Font<'_> {
println!("falling back to encoding {char} -> {s:?}");
s
},
|s| s.clone(),
std::clone::Clone::clone,
);

return s;
Expand Down Expand Up @@ -1088,7 +1088,7 @@ fn get_unicode_map<'a>(doc: &'a Document, font: &'a Dictionary) -> Option<HashMa
}
}
_ => {
panic!("unsupported cmap {:?}", to_unicode)
panic!("unsupported cmap {to_unicode:?}")
}
}
unicode_map
Expand Down Expand Up @@ -1124,7 +1124,7 @@ impl<'a> PdfCIDFont<'a> {
}],
}
} else {
panic!("unsupported encoding {}", name);
panic!("unsupported encoding {name}");
}
}
Object::Stream(stream) => {
Expand All @@ -1133,7 +1133,7 @@ impl<'a> PdfCIDFont<'a> {
adobe_cmap_parser::get_byte_mapping(&contents).unwrap()
}
_ => {
panic!("unsupported encoding {:?}", encoding)
panic!("unsupported encoding {encoding:?}")
}
};

Expand Down Expand Up @@ -1330,10 +1330,7 @@ impl Function {

match function_type {
0 => {
let stream = match obj {
Object::Stream(stream) => stream,
_ => panic!(),
};
let stream = if let Object::Stream(stream) = obj { stream } else { panic!() };
let range: Vec<f64> = get(doc, dict, b"Range");
let domain: Vec<f64> = get(doc, dict, b"Domain");
let contents = get_contents(stream);
Expand Down Expand Up @@ -1370,7 +1367,7 @@ impl Function {
Self::Type2(Type2Func { c0, c1, n })
}
_ => {
panic!("unhandled function type {}", function_type)
panic!("unhandled function type {function_type}")
}
}
}
Expand Down Expand Up @@ -1505,7 +1502,7 @@ fn apply_state(doc: &Document, gs: &mut GraphicsState, state: &Dictionary) {
gs.smask = Some(dict.clone());
}
_ => {
panic!("unexpected smask type {:?}", v)
panic!("unexpected smask type {v:?}")
}
},
b"Type" => match v {
Expand Down Expand Up @@ -1617,7 +1614,7 @@ fn make_colorspace<'a>(doc: &'a Document, name: &[u8], resources: &'a Dictionary
_ => {
let colorspaces: &Dictionary = get(doc, resources, b"ColorSpace");
let cs: &Object = maybe_get_obj(doc, colorspaces, name)
.unwrap_or_else(|| panic!("missing colorspace {:?}", name));
.unwrap_or_else(|| panic!("missing colorspace {name:?}"));

cs.as_array().map_or_else(
|_| {
Expand Down Expand Up @@ -1737,7 +1734,7 @@ fn make_colorspace<'a>(doc: &'a Document, name: &[u8], resources: &'a Dictionary
"DeviceCMYK" => ColorSpace::DeviceCMYK,
"DeviceN" => ColorSpace::DeviceN,
_ => {
panic!("color_space {:?} {:?} {:?}", name, cs_name, cs)
panic!("color_space {name:?} {cs_name:?} {cs:?}")
}
}
},
Expand Down Expand Up @@ -1886,7 +1883,7 @@ impl<'a> Processor<'a> {
show_text(&mut gs, s, &tlm, &flip_ctm, output)?;
}
_ => {
panic!("unexpected Tj operand {:?}", operation)
panic!("unexpected Tj operand {operation:?}")
}
},
"Tc" => {
Expand Down
10 changes: 3 additions & 7 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ impl ExpectedText<'_> {
if let Err(e) = std::fs::create_dir(docs_cache) {
assert!(
(e.kind() == std::io::ErrorKind::AlreadyExists),
"Failed to create directory {}, {}",
docs_cache,
e
"Failed to create directory {docs_cache}, {e}"
);
}
}
Expand All @@ -72,13 +70,11 @@ impl ExpectedText<'_> {
format!("tests/docs/{filename}")
};
let out = extract_text(file_path)
.unwrap_or_else(|e| panic!("Failed to extract text from {}, {}", filename, e));
.unwrap_or_else(|e| panic!("Failed to extract text from {filename}, {e}"));
println!("{out}");
assert!(
out.contains(text),
"Text {} does not contain '{}'",
filename,
text
"Text {filename} does not contain '{text}'"
);
}
}

0 comments on commit 7c34345

Please sign in to comment.