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

bootspec: relax the extensions type #117

Merged
merged 2 commits into from
May 5, 2023
Merged

bootspec: relax the extensions type #117

merged 2 commits into from
May 5, 2023

Conversation

cole-h
Copy link
Member

@cole-h cole-h commented May 5, 2023

Prior to this change, extensions would need to round-trip through serde_json in order to be able to become a given extension type:

let extension: HashMap<String, serde_json::Value> = bootspec.extensions.get("org.test").unwrap();
let extension: OrgTestExtension = serde_json::from_value(serde_json::to_value(extension).unwrap()).unwrap();

Now, however, you can directly deserialize the extension into a type:

let extension: serde_json::Value = bootspec.extensions.get("org.test").unwrap();
let extension: OrgTestExtension = serde_json::from_value(extension).unwrap();
Description
Checklist
  • Built with cargo build
  • Formatted with cargo fmt
  • Linted with cargo clippy
  • Ran tests with cargo test
  • Added or updated relevant tests (leave unchecked if not applicable)
  • Added or updated relevant documentation (leave unchecked if not applicable)

Prior to this change, extensions would need to round-trip through
serde_json in order to be able to become a given extension type:

    let extension: &HashMap<String, serde_json::Value> = bootspec.extensions.get("org.test").unwrap();
    let extension: OrgTestExtension = serde_json::from_value(serde_json::to_value(extension).unwrap()).unwrap();

Now, however, you can directly deserialize the extension into a type:

    let extension: &serde_json::Value = bootspec.extensions.get("org.test").unwrap();
    let extension: OrgTestExtension = serde_json::from_value(extension.to_owned()).unwrap();
Internal nulls are not specified (read: allowed).
@@ -35,6 +35,14 @@ impl<'de> Visitor<'de> for BootSpecExtensionsVisitor {
map.insert(key, value);
}

for (k, v) in map.iter() {
if v.is_null() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this doesn't preclude e.g. "org.test": { "enableSomeSetting": null } -- only "org.test": null

@cole-h cole-h merged commit e7eeca8 into main May 5, 2023
5 checks passed
@cole-h cole-h deleted the relax-extensions-type branch May 5, 2023 20:15
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.

None yet

2 participants