Skip to content

Commit

Permalink
📝 Example with EventReader (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
punkstarman authored Sep 18, 2021
1 parent 4a3b6bd commit 2d2e864
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,37 @@
//! assert_eq!(plate_appearance.events[0], Event::Pitch(Pitch { speed: 95, r#type: PitchType::FourSeam, outcome: PitchOutcome::Ball }));
//! }
//! ```
//!
//! ## Custom EventReader
//!
//! ```rust
//! use serde::Deserialize;
//! use serde_derive::{Deserialize, Serialize};
//! use serde_xml_rs::{from_str, to_string, de::Deserializer};
//! use xml::reader::{EventReader, ParserConfig};
//!
//! #[derive(Debug, Serialize, Deserialize, PartialEq)]
//! struct Item {
//! name: String,
//! source: String,
//! }
//!
//! fn main() {
//! let src = r#"<Item><name> Banana </name><source>Store</source></Item>"#;
//! let should_be = Item {
//! name: " Banana ".to_string(),
//! source: "Store".to_string(),
//! };
//!
//! let config = ParserConfig::new()
//! .trim_whitespace(false)
//! .whitespace_to_characters(true);
//! let event_reader = EventReader::new_with_config(src.as_bytes(), config);
//! let item = Item::deserialize(&mut Deserializer::new(event_reader)).unwrap();
//! assert_eq!(item, should_be);
//! }
//! ```
//!
pub mod de;
mod error;
Expand Down

0 comments on commit 2d2e864

Please sign in to comment.