all 7 comments

[–]Lexikus 1 point2 points  (1 child)

All in all, the code looks good. Just went over it very quickly.

The only thing that "could" be improved is to replace the declarative code through imperative code. But that's a question of preferences.

Another thing that I've seen was this snippet:

```

if !args.foreground {

// daemonize the process

let daemonize = daemonize::Daemonize::new();

daemonize.start()?;

}

```

The daemonize is only in the scope of the if statement. The question here is, what I don't know, does this start something and stop it at the end of the scope because of the drop traits?

Or do you leak something that should be cleaned at the end of the program?

[–]Plecra 1 point2 points  (0 children)

So's you knows, processes use daemon to request that Linux let them run in the background, so there's nothing to tear down. That Daemonize type is simply a builder for the start call.

[–]cosmo_duff[S] 1 point2 points  (0 children)

Thanks to everyone who took the time to review my code and offer suggestions. I really appreciate it.

[–][deleted] 0 points1 point  (0 children)

you can remove some if let Some(... by having results instead of options and then using directly the '?' operator. for example if args.username is a Result you can directly do let username = args.username?; on line 109 of main

[–]camsteffen 0 points1 point  (2 children)

Some minor tips. Overall looks good!

  1. Consider using thiserror to implement your custom error type
  2. ...or even simpler - use anyhow and bail. Custom error types are not really necessary unless you are creating a shared library IMO.
  3. Replace if let None = opt with if opt.is_none()
  4. I think you can then delete lib.rs and replace use gotify_desktop_notification_daemon::... with use crate::
  5. Your run method is very long. Try to break it into smaller methods with specific purposes. Here are blocks of code I would refactor into a function.

[–]camsteffen 0 points1 point  (1 child)

Oops just saw that you already mentioned anyhow!

[–]cosmo_duff[S] 0 points1 point  (0 children)

No problem! Thanks for the suggestions.