tokio-rs / valuable

MIT License
185 stars 19 forks source link

question: is valuable expected to work with tracing macros? #115

Closed OliverNChalk closed 11 months ago

OliverNChalk commented 1 year ago

I was expecting valuable to work out of the box with tracing's macros (info, debug etc). However, I get an issue saying Value is not implemented for my type (i.e. there is no blanket implementation covering all types that implement Valuable). This currently seems like the only way to make tracing happy:

for (service, old_state) in removed {
    info!(service = &service as &dyn Valuable,"Service unit removed");
    self.service_state.remove(&service);
}

Please let me know if this was an oversight, or if there's a fundamental limitation preventing the compiler from auto-coercing my type (RemoteServiceId) that implements Valuable to Value?

fluffysquirrels commented 11 months ago

First you need to enable the tracing_unstable rustc flag and the valuable feature in the tracing crate. Ref.

Then you need to call .as_value() on the value before using a tracing macro, e.g.:

tracing::info!(service = service.as_value(), "Service unit removed");