Repository navigation
feat(variables): Introduce new schema #2065
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
Changes from all commits
eca34e5
9ba3d83
1205528
c579964
1beb1fe
b33ea59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| //! Contains types for representing variable values. | ||
|
|
||
| use std::collections::BTreeMap; | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
| use symbolic::debuginfo::VariableKind as SymbolicVariableKind; | ||
|
|
||
| /// Variables keyed by their names. | ||
| #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(transparent)] | ||
| pub struct Variables(BTreeMap<String, Variable>); | ||
|
|
||
| impl Variables { | ||
| pub fn is_empty(&self) -> bool { | ||
|
Member
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. I think depending on usage we could also impl
Member
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. I don't think that is a good idea. I intentionally encapsulated this because we may want to switch to a different type that would allow multiple variables with the same name, which Implementing |
||
| self.0.is_empty() | ||
| } | ||
| } | ||
|
|
||
| impl<S> FromIterator<(S, Variable)> for Variables | ||
| where | ||
| S: Into<String>, | ||
| { | ||
| fn from_iter<T>(iter: T) -> Self | ||
| where | ||
| T: IntoIterator<Item = (S, Variable)>, | ||
| { | ||
| Self(iter.into_iter().map(|(k, v)| (k.into(), v)).collect()) | ||
| } | ||
| } | ||
|
|
||
| /// A variable extracted from a memory dump. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct Variable { | ||
| kind: VariableKind, | ||
| #[serde(rename = "type")] | ||
| ty: String, | ||
| #[serde(flatten)] | ||
| value: Value, | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| /// The variable's kind (e.g. local or parameter). | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum VariableKind { | ||
| Local, | ||
| Parameter, | ||
| } | ||
|
|
||
| /// A value of a variable or field within a variable (e.g. list item, pointee, struct field). | ||
| /// | ||
| /// This struct allows for multiple co-existing representations. | ||
| #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct Value { | ||
| /// A fully-formatted, source-specific representation of a variable value. | ||
| /// | ||
| /// This should typically be used for primitive types like integers, booleans, chars. | ||
| value: Option<String>, | ||
| } | ||
|
|
||
| impl Value { | ||
| /// Create a new empty [`Value`]. | ||
| pub fn new() -> Self { | ||
| Self::default() | ||
| } | ||
|
|
||
| /// Provide a fully-formatted, source-specific representation of the [`Value`]. | ||
| /// | ||
| /// This should typically be used for primitive types like integers, booleans, and chars. | ||
| pub fn value(self, value: Option<String>) -> Self { | ||
| Self { value } | ||
| } | ||
|
|
||
| /// Convert this [`Value`] into a [`Variable`] with the given type and kind. | ||
| pub fn into_variable<T, K>(self, ty: T, kind: K) -> Variable | ||
| where | ||
| T: Into<String>, | ||
| K: Into<VariableKind>, | ||
| { | ||
| Variable { | ||
| kind: kind.into(), | ||
| ty: ty.into(), | ||
| value: self, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<SymbolicVariableKind> for VariableKind { | ||
| fn from(value: SymbolicVariableKind) -> Self { | ||
| match value { | ||
| SymbolicVariableKind::Parameter => VariableKind::Parameter, | ||
| SymbolicVariableKind::Local => VariableKind::Local, | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.