Add a Rust example for the NVDA Controller Client#15771
Conversation
|
@DataTriny Given your previous investment in NVDA Controller examples and you're much more experienced with Rust than I am, could you have a quick look at the code please? |
|
Sure I will. I'm away from home until next wednesday though.
Le sam. 11 nov. 2023 à 11:26, Leonard de Ruijter ***@***.***>
a écrit :
… @DataTriny <https://github.com/DataTriny> Given your previous investment
in NVDA Controller examples and you're much more experienced with Rust than
I am, could you have a quick look at the code please?
—
Reply to this email directly, view it on GitHub
<#15771 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC3JTEFWVREFMBIVZ5WLJW3YD5HEJAVCNFSM6AAAAAA7HFBEUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBWG43TMNRVGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
DataTriny
left a comment
There was a problem hiding this comment.
Minor suggestions from me. Looks good overall!
| 0 | ||
| } | ||
|
|
||
| fn main() { |
There was a problem hiding this comment.
I'd try to have the main function return Result<()> and remove the calls to Result::unwrap in favor of the ? operator. The call to Result::expect can stay since it provides a clearer error message.
There was a problem hiding this comment.
Thanks, good idea!
| pub type OnSsmlMarkReached = onSsmlMarkReachedFuncType; | ||
|
|
||
| pub fn test_if_running() -> Result<()> { | ||
| let res = WIN32_ERROR(unsafe { nvdaController_testIfRunning() }); |
There was a problem hiding this comment.
I think you might be able to come up with a generic function to encapsulate your error handling logic and not repeat it everywhere right?
| Ok(()) | ||
| } | ||
|
|
||
| pub fn braille_message(mesage: &str) -> Result<()> { |
There was a problem hiding this comment.
| pub fn braille_message(mesage: &str) -> Result<()> { | |
| pub fn braille_message(message: &str) -> Result<()> { |
| } | ||
|
|
||
| pub fn braille_message(mesage: &str) -> Result<()> { | ||
| let message = HSTRING::from(mesage); |
There was a problem hiding this comment.
| let message = HSTRING::from(mesage); | |
| let message = HSTRING::from(message); |
Co-authored-by: Arnold Loubriat <datatriny@gmail.com>
|
@DataTriny Thanks a lot for your review. I think I have addressed everything. |
|
|
||
| pub type OnSsmlMarkReached = onSsmlMarkReachedFuncType; | ||
|
|
||
| fn is_succes(error: u32) -> Result<()> { |
There was a problem hiding this comment.
Sadly you have a typo here. Maybe to_result(status: u32) would be more appropriate?
There was a problem hiding this comment.
Thanks, I'll rename accordingly.
| pub type OnSsmlMarkReached = onSsmlMarkReachedFuncType; | ||
|
|
||
| fn is_succes(error: u32) -> Result<()> { | ||
| let res = WIN32_ERROR(error); |
There was a problem hiding this comment.
Having read windows-rs's doc, I think you should use WIN32_ERROR::ok instead of your if statement.
There was a problem hiding this comment.
That's a very good catch, thanks! Function can now be a one liner.
Co-authored-by: Arnold Loubriat <datatriny@gmail.com>
DataTriny
left a comment
There was a problem hiding this comment.
I think this is a good start for anyone interested in communicating with NVDA from a Rust program. Good job @LeonarddeR!
|
Thank you very much @DataTriny! |
| // Copyright(C) 2023 NV Access Limited, Leonard de Ruijter | ||
| // This file is covered by the GNU Lesser General Public License, version 2.1. | ||
| // See the file license.txt for more details. |
There was a problem hiding this comment.
could you use the more standard python headers? we don't have a license.txt, we use "COPYING"
There was a problem hiding this comment.
There is a license.txt in the controllerClient folder.
There was a problem hiding this comment.
Alternatively, if the mention of licence.txt is confusing, you can just use the copyright header for LGPL licensed code from our copyright headers wiki page
There was a problem hiding this comment.
Thanks @lukaszgo1, I wasn't aware of these guidelines on the wiki.
There was a problem hiding this comment.
Could this be moved to "Changes to the NVDA Controller Client library:"
Link to issue number:
None
Summary of the issue:
The rust programming language is becoming more and more relevant, yet an example for the NVDA controller client is missing.
Description of user facing changes
None.
Description of development approach
Add a rust example, based on a workspace with two crates:
Testing strategy:
Test steps are in readme.md
Known issues with pull request:
This is blocked by #15734 for now.
Code Review Checklist: