From 8818a94ad79ebdebdf4c7819bd42e363c63bd630 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 9 May 2023 20:38:46 +0200 Subject: feat: add optional deserializer generics static bounds --- src/deserializer/buffered.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/deserializer/buffered.rs') diff --git a/src/deserializer/buffered.rs b/src/deserializer/buffered.rs index 7a6058b..6568910 100644 --- a/src/deserializer/buffered.rs +++ b/src/deserializer/buffered.rs @@ -5,25 +5,29 @@ use std::io::BufRead; use quick_xml::events::Event; use quick_xml::Reader; -use crate::deserializer::{Deserializer, Error, IgnoreEnd}; +use crate::deserializer::{Deserializer, Error, IgnoreEnd, MaybeStatic}; use crate::event::EventExt; use crate::tagged::TagStart; +use crate::util::trait_alias; use crate::DeserializeTagged; +trait_alias! { + /// A XML deserializer source with an internal buffer. + pub Source: BufRead + MaybeStatic; +} + /// XML deserializer using a source which has an internal buffer. -pub struct Buffered +pub struct Buffered { - reader: Reader, + reader: Reader, leftover_event: Option>, buf: Vec, } -impl Buffered -where - Source: BufRead, +impl Buffered { /// Returns a new [`Buffered`]. - pub fn new(source: Source) -> Self + pub fn new(source: TSource) -> Self { let mut reader = Reader::from_reader(source); @@ -38,9 +42,7 @@ where } } -impl Deserializer for Buffered -where - Source: BufRead, +impl Deserializer for Buffered { fn de_tag( &mut self, @@ -84,9 +86,9 @@ where Ok(deserialized) } - fn de_tag_list( + fn de_tag_list>( &mut self, - tag_name: Option<&str>, + tag_name: Option, ) -> Result, Error> { let mut deserialized_items = Vec::new(); @@ -94,10 +96,10 @@ where loop { let start = match self.read_event()? { Event::Start(start) - if tag_name.map_or_else( + if tag_name.as_ref().map_or_else( || true, |expected_tag_name| { - start.name().as_ref() == expected_tag_name.as_bytes() + start.name().as_ref() == expected_tag_name.as_ref().as_bytes() }, ) => { @@ -174,9 +176,7 @@ where } } -impl Buffered -where - Source: BufRead, +impl Buffered { fn read_end_event(&mut self, tag_name: &[u8]) -> Result<(), Error> { -- cgit v1.2.3-18-g5258