Beginner Seeking Pointers/Tips on Code

Hello, I am new to Rust, I was hoping if anyone had the time they could look over my code and give feedback. Just things like poor practices, beginner mistakes, etc. Thank you in advance!

Hello, welcome to the Rust forums! I've never used Amazon CloudWatch, so I can't test there, but here are some things I noticed while reading your code:

  1. When logging, please do not require log messages to be Strings. This adds extra overhead that isn't necessary because the messages will not be mutated after creation. Instead, use a str reference like &'a str. You will need to add lifetimes to your LogLevel enum, but it will make your library a lot more friendly.
  2. Less of a critique, but perhaps you could add a library feature that toggles on and off the color code formatting when logging. Codes like \x1b[0m do not work on certains platforms, like some Windows versions. (I'm pretty sure the old cmd.exe doesn't support them, but I haven't tested it.)
  3. I'm noticing a frequent use of <br><br> in your documentation. In general that shouldn't be necessary and makes reading the un-rendered code comments more difficult. You can test the documentation output with cargo doc.
  4. In, you re-export items from the prelude. This is more of a style thing, but usually re-exports from the actual modules and the prelude re-exports from (or the modules directly). This isn't big though, so you don't need to change it.
  5. I recommend running your code through rustfmt and clippy to catch any other mistakes that I missed.

That's all that I've seen so far without extensively going over your code. Some of the things look quite professional, so good job! I hope that you've enjoyed using Rust. :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.