-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tracing-tracy: replace baked-in config fields with a Config
trait
#91
Conversation
In the 2nd commit I went ahead and added an example of how |
bb60392
to
300b61d
Compare
type Formatter: for<'writer> FormatFields<'writer> + 'static; | ||
|
||
/// Use a custom field formatting implementation. | ||
fn formatter(&self) -> &Self::Formatter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish there was a way to specify a default here. Sadly not much progress: https://rust-lang.github.io/rfcs/2532-associated-type-defaults.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish it was possible too, however even with ATDs it wouldn’t be possible as the method returns a reference to &self
and traits do not have access to fields. Achieving this would need something like rust-lang/rfcs#1546.
/// report the issues in whatever way they wish to. | ||
/// | ||
/// By default a message coloured in red is emitted to the tracy client. | ||
fn on_error(&self, client: &Client, error: &'static str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooooh, this is quite a nice flexibility improvement.
This allows users to more flexibly adjust the behaviour of the tracing layer. My favourite examples are actually an ability to implement this structure for some other serialization format that holds the application-wide config. That way people do not need to litter their application set up code with accesses to their configuration, conversion and other concerns. But with this if people want constant evaluation for performance critical applications, now they can do it too.
In practice I have found that, whenever a library provides an ability to configure through a trait generic and then provides a basic runtime cofniguration convenience-type, the convenience type ends up being dropped in favour of a manual implementation pretty quickly. So it seems like a not-terrible-idea to just push users to the trait immediately? And we don’t need to figure a good design for a compile-time configuration type… Might still go back on this decision, idk.
744afce
to
a9e4c24
Compare
This allows users to more flexibly adjust the behaviour of the tracing layer. My favourite examples are actually an ability to implement this structure for some other serialization format that holds the application-wide config. That way people do not need to litter their application set up code with accesses to their configuration, conversion and other concerns.
But with this if people want constant evaluation for performance critical applications, now they can do it too.