Skip to main content

serde_xpath/
lib.rs

1pub mod de;
2pub mod error;
3pub mod xpath;
4
5pub use de::__private;
6pub use error::Error;
7pub use serde_xpath_derive::Deserialize;
8
9/// Marker type for extracting text content from an element
10pub struct Text;
11
12/// Trait for types that can be deserialized from XML using XPath
13pub trait FromXml: Sized {
14    fn from_xml(xml: &str) -> Result<Self, Error>;
15}
16
17/// Deserialize a type from an XML string
18pub fn from_str<T: FromXml>(s: &str) -> Result<T, Error> {
19    T::from_xml(s)
20}
21
22/// Deserialize a type from an XML string using the XPath-based deserializer
23/// This is called by the generated Deserialize implementations
24pub fn from_str_with_descriptor<T, F>(
25    s: &str,
26    descriptor: &__private::StructDescriptor,
27    field_deserializer: F,
28) -> Result<T, Error>
29where
30    F: FnOnce(__private::StructFieldDeserializer<'_, '_>) -> Result<T, Error>,
31{
32    __private::deserialize_xpath_struct(s, descriptor, field_deserializer)
33}