-
Notifications
You must be signed in to change notification settings - Fork 28
refactor!: rework TaskLocalDiagnostic #234
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
Open
tisonkun
wants to merge
6
commits into
main
Choose a base branch
from
task-local
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−63
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,17 @@ pub trait Visitor { | |
| fn visit(&mut self, key: KeyView, value: ValueView) -> Result<(), Error>; | ||
| } | ||
|
|
||
| impl<F> Visitor for F | ||
| where | ||
| F: FnMut(KeyView, ValueView) -> Result<(), Error>, | ||
| { | ||
| fn visit(&mut self, key: KeyView, value: ValueView) -> Result<(), Error> { | ||
| self(key, value) | ||
| } | ||
| } | ||
|
Comment on lines
+33
to
+40
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly should be better. But this impl looks very common to support; as in this PR: diag.visit(&mut |key: KeyView<'_>, value: ValueView<'_>| {
assert_eq!(key.as_str(), "key");
assert_eq!(value.to_str().unwrap(), "value");
Ok(())
})
.unwrap(); |
||
|
|
||
| /// A key in a key-value pair. | ||
| #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
| #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
| pub struct Key<'a>(RefStr<'a>); | ||
|
|
||
| impl fmt::Display for Key<'_> { | ||
|
|
@@ -80,6 +89,19 @@ impl Key<'_> { | |
| #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
| pub struct KeyOwned(Cow<'static, str>); | ||
|
|
||
| macro_rules! impl_key_owned_from { | ||
| ($ty:ty) => { | ||
| impl From<$ty> for KeyOwned { | ||
| fn from(v: $ty) -> Self { | ||
| KeyOwned(Cow::from(v)) | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| impl_key_owned_from!(&'static str); | ||
| impl_key_owned_from!(String); | ||
|
|
||
| impl Borrow<str> for KeyOwned { | ||
| fn borrow(&self) -> &str { | ||
| &self.0 | ||
|
|
@@ -117,7 +139,7 @@ impl KeyOwned { | |
| } | ||
|
|
||
| /// A borrowed view of a key in a key-value pair. | ||
| #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
| #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
| pub struct KeyView<'a>(RefStr<'a>); | ||
|
|
||
| impl Borrow<str> for KeyView<'_> { | ||
|
|
@@ -341,10 +363,10 @@ impl<'a> Iterator for MapValueIter<'a> { | |
| } | ||
|
|
||
| /// A borrowed value in a key-value pair. | ||
| #[derive(Debug, Clone)] | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct Value<'a>(ValueState<'a>); | ||
|
|
||
| #[derive(Clone)] | ||
| #[derive(Clone, Copy)] | ||
| enum ValueState<'a> { | ||
| None, | ||
| Bool(bool), | ||
|
|
@@ -513,6 +535,26 @@ enum ValueOwnedState { | |
| Map(Box<HashMap<KeyOwned, ValueOwned>>), | ||
| } | ||
|
|
||
| macro_rules! impl_value_owned_from { | ||
| ($ty:ty, $new:ident) => { | ||
| impl From<$ty> for ValueOwned { | ||
| fn from(v: $ty) -> Self { | ||
| Self::$new(v) | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| impl_value_owned_from!(bool, bool); | ||
| impl_value_owned_from!(i64, i64); | ||
| impl_value_owned_from!(u64, u64); | ||
| impl_value_owned_from!(f64, f64); | ||
| impl_value_owned_from!(i128, i128); | ||
| impl_value_owned_from!(u128, u128); | ||
| impl_value_owned_from!(char, char); | ||
| impl_value_owned_from!(String, str); | ||
| impl_value_owned_from!(&'static str, str); | ||
|
|
||
| #[cfg(feature = "serde")] | ||
| impl serde::Serialize for ValueOwned { | ||
| fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
|
|
@@ -614,7 +656,7 @@ impl ValueOwned { | |
| } | ||
|
|
||
| /// A borrowed view of a value. | ||
| #[derive(Debug, Clone)] | ||
| #[derive(Debug, Clone, Copy)] | ||
| #[non_exhaustive] | ||
| pub enum ValueView<'a> { | ||
| /// The absence of a value. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure if we can ensure View and Borrowed Key/Value always
Copybut I suggest it is the right design and we should keep it as much as possible.