Skip to content

Commit

Permalink
Add from_node function
Browse files Browse the repository at this point in the history
  • Loading branch information
wspeirs authored and adamreichold committed Aug 15, 2023
1 parent 4858fb0 commit 356fc87
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,21 @@ where
from_doc(&document)
}

/// Deserialize an instance of type `T` from a [`roxmltree`] document
/// Deserialize an instance of type `T` from a [`roxmltree::Document`]
pub fn from_doc<'de, 'input, T>(document: &'de Document<'input>) -> Result<T, Error>
where
T: de::Deserialize<'de>,
{
from_node(document.root_element())
}

/// Deserialize an instance of type `T` from a [`roxmltree::Node`]
pub fn from_node<'de, 'input, T>(node: Node<'de, 'input>) -> Result<T, Error>
where
T: de::Deserialize<'de>,
{
let deserializer = Deserializer {
source: Source::Node(document.root_element()),
source: Source::Node(node),
visited: &mut HashSet::new(),
};
T::deserialize(deserializer)
Expand Down

0 comments on commit 356fc87

Please sign in to comment.