Return result of Command::execute
directly from main
#7
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: ryze/ff2mpv-rust#7
Loading…
Reference in a new issue
No description provided.
Delete branch "main-returns-result"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Since
Result
implementsTermination
, the result ofCommand::execute
can be returned frommain
directly. If anFF2MpvError
error would be propagated tomain
, it will be printed usingeprintln
just as before, and the program will terminate with an appropriate exit code: https://doc.rust-lang.org/std/process/struct.ExitCode.html#associatedconstant.FAILUREThe only caveat is that
FF2MpvError
has to implementDebug
, but instead of deriving it I cheated a bit and re-used the existingDisplay
implementation to preserve the format of the error messages.Thanks for this helpful little program 💚
I don't think this is meant to be used in production code (note it uses
Debug
trait instead ofDisplay
). This requires Rust's "runtime" to wrap themain
function and handle error outside of the developer's control. ReturningResult
frommain
should be used for faster prototyping and never appear in release, at least in my opinion.No follow up in a month, closing
Pull request closed