Skip to content

Commit

Permalink
add xml_str_to_json function
Browse files Browse the repository at this point in the history
this allows us to prevent unnecessary String allocations for
something that is eventually turned into a slice anyway
  • Loading branch information
cjschneider2 committed Jan 27, 2022
1 parent 5c884d5 commit 4f05ad2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ pub fn xml_string_to_json(xml: String, config: &Config) -> Result<Value, Error>
Ok(xml_to_map(&root, config))
}

/// Converts the given XML string into `serde::Value` using settings from `Config` struct.
pub fn xml_str_to_json(xml: &str, config: &Config) -> Result<Value, Error> {
let root = Element::from_str(xml)?;
Ok(xml_to_map(&root, config))
}

/// Returns a tuple for Array and Value enforcements for the current node or
/// `(false, JsonArray::Infer(JsonType::Infer)` if the current path is not found
/// in the list of paths with custom config.
Expand Down

0 comments on commit 4f05ad2

Please sign in to comment.