Skip to content
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

Remove Report/ReportKind lifetime #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

p-lindberg
Copy link

This PR suggests a refactor of enum ReportKind<'a> into trait ReportKind in order to get rid of the lifetime parameter. The default kinds Error, Warning and Advice are instead represented using empty structs that implement the trait. Custom report kinds can now instead be defined by implementing the ReportKind trait for new types (with or without lifetime parameters).

The motivation for this change is that the lifetime on Report, which stems specifically from ReportKind::Custom, only serves a purpose in the specific case where a custom report kind is used with a borrowed string, while being superfluous in other cases. If you're not using custom report kinds and want to be able to return reports from functions or store them in structs, you have to stick with Report<'static> everywhere, which feels unnecessary.

Bonus: a custom report kind should now only be colored if the Config has colors enabled. I assume this was a bug.

Note that this PR contains breaking changes to the public API, specifically the change of ReportKind from enum to trait, and the introduction of default trait implementations replacing the enum variants. If this is a concern, it might be possible to keep the old enum and make function signatures backwards compatible using generics, but I haven't looked into it.

…, avoiding the extra lifetime to support custom report kinds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant