local-group / rust-escposify

A ESC/POS driver in Rust ( Documentation: https://docs.rs/escposify )
MIT License
53 stars 18 forks source link

Report IO result for each method call on Printer #7

Closed Masterchef365 closed 5 years ago

Masterchef365 commented 5 years ago

Each call to the printer has the potential to fail due to IO errors. Instead of ignoring these, the method should return the result. If one method call results in several writes, the total of their written bytes is returned.

TheWaWaR commented 5 years ago

I just merge a bug fix, please rebase to resolve the conflict.

Masterchef365 commented 5 years ago

Alright, I finished rebasing. I haven't added InvalidData yet because I'm not sure if InvalidInput would be a better choice?

TheWaWaR commented 5 years ago

InvalidData Data not valid for the operation were encountered.

Unlike InvalidInput, this typically means that the operation parameters were valid, however the error was caused by malformed input data.

For example, a function that reads a file into a string will error with InvalidData if the file's contents are not valid UTF-8.

As I understand:

File

Printer

Masterchef365 commented 5 years ago

Ah okay that makes much more sense. I've replaced all of the panic!()s with return Err(InvalidData,...). Let me know if I missed anything more.

TheWaWaR commented 5 years ago

Thanks

TheWaWaR commented 5 years ago

@Masterchef365
Add some related chain call API, and added a release note (v0.3.0)

Also published to crates.io (https://crates.io/crates/escposify/0.3.0)