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:
- When logging, please do not require log messages to be
String
s. This adds extra overhead that isn't necessary because the messages will not be mutated after creation. Instead, use astr
reference like&'a str
. You will need to add lifetimes to yourLogLevel
enum, but it will make your library a lot more friendly. - 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 oldcmd.exe
doesn't support them, but I haven't tested it.) - 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 withcargo doc
. - In
lib.rs
, you re-export items from the prelude. This is more of a style thing, but usuallylib.rs
re-exports from the actual modules and the prelude re-exports fromlib.rs
(or the modules directly). This isn't big though, so you don't need to change it. - 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.
1 Like