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

fix: handle rust types #47

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Prathiksha-Nataraja
Copy link
Contributor

Pull Request Template

Description

Handle the rustypes List, Tuple, HashMap, Struct

Please select the options that are relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • Pull Request follow only a single responsibility.
  • Code follows the style guidelines of this project
  • Performed a self-review of my own code
  • Commented my code, particularly in hard-to-understand areas
  • Made corresponding changes to the documentation
  • Changes generate no new warnings
  • Added tests that prove fix is effective or the feature works
  • New and existing unit tests pass locally with the changes
  • Any dependent changes have been merged and published in downstream modules
  • Checked the code and corrected any misspellings

}
}
RustType::Int => {
if key.parse::<i64>().is_err() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON key should be in string format

test/main.echo Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove echo file

@@ -1,3 +1,5 @@
use rayon::collections::btree_map::IterMut;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused imports

}
let parsed_value = serde_json::from_str(&value_str)?;
validate_value(&parsed_value, &input_type)?;
// validate_value(&serde_json::from_str(&value_str)?, &input_type)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code clean up

(serde_json::Value::Number(number), value) if number.is_f64() => {
validate_value(value, value_type)?
}
(serde_json::Value::Bool(bool_value), value) => validate_value(value, value_type)?,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation for tuple types, hashmaps, arrays, and similar structures is not handled.

@@ -1,5 +1,83 @@
use super::*;
use anyhow::anyhow;

fn validate_value(value: &serde_json::Value, expected_type: &RustType) -> anyhow::Result<()> {
match expected_type {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation for Value type not handled.

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.

2 participants