Converting png/jpeg image to WebP

Here's a version rewritten to return (opaque) errors and to use Path and PathBuf instead of Strings. Feel free to take what you like, no credit needed.

Some specific notes:

  • I didn't see any reason for this to be async
  • You almost always want to take a &str instead of a &String
    • But here you want a &Path
    • Or the generic version I used, which is less typing for users of the function, at the cost of more monomorphizing. Many libraries, including std, use this convention
  • Even if you're only ever going to unwrap returned errors, you can see how much the ability to use ? can clean up your code
    • You could always have a wrapper that unwraps if it's a bother
1 Like