Extract structs that encode announcements to users#194
Extract structs that encode announcements to users#194tummychow merged 1 commit intotummychow:masterfrom
Conversation
tummychow
left a comment
There was a problem hiding this comment.
ah, so you chose to roll it yourself, not bad
src/lib.rs
Outdated
| /// normal operations (not debug messages). | ||
| trait Announceable { | ||
| fn announce_to(&self, logger: &slog::Logger); | ||
| } |
There was a problem hiding this comment.
rather than having a trait implemented by each announcement, it would be tidier to have an enum comprising all possible announcements...
src/lib.rs
Outdated
| } | ||
|
|
||
| fn announce<T: Announceable>(logger: &slog::Logger, announcement: T) { | ||
| announcement.announce_to(logger); |
There was a problem hiding this comment.
... and then instead of calling a method, announce simply matches on the enum. the match will be long ofc, but not that different to the current arrangement of code
There was a problem hiding this comment.
Ah. rust has "rich enums" of a sort. Learning things every day.
I think I did the thing you asked.
I just amended because there's a lot of churn between the two commits; no benefit in seeing the wandering path, IMO.
9cc6ad5 to
1cd6eb8
Compare
Sometimes "didn't know any better options" can look like "chose". The only other thing I was aware of that would do something close to this was the slog::Value, but it looked to me like this is great for logging parts of the msg, but not the key-value pairs. |
1cd6eb8 to
d7cadda
Compare
Part of #192.
Does not aid testability at this point, but provides a consistent mechanism for creating "announcements" that are conveyed to the user during normal (or even abnormal operation). Helps ensure these are properly crafted and distinguishes them from debug-logs.