Use thiserror for error handling with less boilerplate

This commit is contained in:
Steve Cook
2023-02-20 09:41:28 -05:00
parent 01e4f4a126
commit f8b29f37db
135 changed files with 868 additions and 905 deletions

View File

@@ -57,11 +57,11 @@ impl SVGLuminanceSource {
pub fn new(svg_data: &[u8]) -> Result<Self> {
// Load the SVG file
let Ok(tree) = resvg::usvg::Tree::from_data(svg_data, &Options::default()) else {
return Err(Exceptions::formatWith(format!("could not parse svg data: {}", "err")));
return Err(Exceptions::format_with(format!("could not parse svg data: {}", "err")));
};
let Some(mut pixmap) = resvg::tiny_skia::Pixmap::new(tree.size.width() as u32, tree.size.height() as u32) else {
return Err(Exceptions::formatWith("could not create pixmap"));
return Err(Exceptions::format_with("could not create pixmap"));
};
resvg::render(
@@ -72,7 +72,7 @@ impl SVGLuminanceSource {
);
let Some(buffer) = RgbaImage::from_raw(tree.size.width() as u32, tree.size.height() as u32, pixmap.data().to_vec()) else {
return Err(Exceptions::formatWith("could not create image buffer"));
return Err(Exceptions::format_with("could not create image buffer"));
};
// let Ok(image) = image::load_from_memory_with_format(pixmap.data(), image::ImageFormat::Bmp) else {