Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant