Skip to content

Commit

Permalink
Merge pull request #279 from dralley/master
Browse files Browse the repository at this point in the history
Add a from_slice() function like other serde datatype libraries
  • Loading branch information
tafia authored Mar 31, 2021
2 parents 2032228 + 0661a31 commit a4be484
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ pub struct Deserializer<R: BufRead> {
has_value_field: bool,
}

/// Deserialize a xml string
/// Deserialize an instance of type T from a string of XML text.
pub fn from_str<T: DeserializeOwned>(s: &str) -> Result<T, DeError> {
from_reader(s.as_bytes())
}

/// Deserialize an instance of type T from bytes of XML text.
pub fn from_slice<T: DeserializeOwned>(b: &[u8]) -> Result<T, DeError> {
from_reader(b)
}

/// Deserialize from a reader
pub fn from_reader<R: BufRead, T: DeserializeOwned>(reader: R) -> Result<T, DeError> {
let mut de = Deserializer::from_reader(reader);
Expand Down

0 comments on commit a4be484

Please sign in to comment.