Die on missing uinput - #1
Open
david-soto-m wants to merge 3 commits into
Open
Conversation
Author
|
So I added another commit in which I changed some When there is a possible panic, you can avoid it occurring in the function by retuning an |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I saw your PR and saw that you requested some feedback on the Rust code. I must say that I am not really experienced, so take everything I say with a critical eye.
The return type
The main thing that I would change is the return Type. You use a boolean and then panic when it's false. I have used a Result type. The Result type has the benefit of forcing the user of your function to handle a possible error. Whether to panic or to try something else or set a default, the user is forced to do something with it. This is not the case with a bool type.
Another benefit of returning a Result is that every behaviour of your functionality is now inside your function, including information inside your panic messages.
returns a
See how the user of the function has had to call unwrap on the function result. If they didn't it wouldn't compile.
In the first commit I returned a standard result, but I later found out about the Kbct Error type and I have corrected that in the second commit.
()is the unit type in rust and the compiler knows how to optimize it and is frequently used in these cases. It's an empty tuple.Aesthetics
The other changes I made are related to cargo-fmt and cargo-clippy- They are some really useful tools for Rust development.
fmt is a linter, that enforces style. It's used by running
cargo fmt. This avoided long lines, mostly.clippy is a tool that checks your code for common improvements and mistakes. It's used by running
cargo clippy. This avoided an unneeded clone.Currently, there is a lot that both those tools do, and I will make a PR with all the fixes they suggest to the main project, after they accept yours.
Else
If you are interested in learning Rust, I would recommend going through the rust book.
Sorry for my English