Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update rust binary module to current standards #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Follpvosten
Copy link

I saw that the rust example module was in a really bad shape, so I updated it to better fit current standards.

Changes include:

  • updated to 2018 edition (no more extern crate, macros are imported using use statements)
  • replaced read_file_contents helper method with std::fs::read_to_string
  • moved logic to a separate function returning a result to streamline error handling
  • got rid of the exit_json and fail_json functions since terminating the process in random functions is kind of a code smell in Rust
    • instead, in a more functional way, there is one result from the program and main() handles how to return it
  • added anyhow as a dependency to help with error handling (there are other ways to do that, but those would either require a lot more boilerplate or remove context from the errors)

All in all, main.rs now has half the amount of lines and is much closer to idiomatic Rust.

If there are any other changes I should make to this, please tell me. I'm also thinking about writing an ansible_module library for Rust, streamlining the experience further, but I think this is a good first step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant