From e19da101f5bd319a20165ae8614e6022f763d65c Mon Sep 17 00:00:00 2001 From: fxpineau Date: Tue, 17 Oct 2023 13:17:37 +0200 Subject: [PATCH] Fix 'write_from_data_end' --- src/resource.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/resource.rs b/src/resource.rs index 70d9924..909d032 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -673,27 +673,26 @@ impl Resource { let tag = BytesStart::borrowed_name(Self::TAG_BYTES); let mut iter = self.sub_elems.iter_mut(); let mut table_found = false; - while !table_found { - if let Some(se) = iter.next() { - if match &mut se.resource_or_table { - ResourceOrTable::Resource(resource) => { - resource.write_from_data_end(writer, &(), start_after_data) - } - ResourceOrTable::Table(table) => table - .write_from_data_end(writer, &(), start_after_data) - .map(|()| true), - }? { - table_found = true; - for info in se.infos.iter_mut() { - info.write(writer, context)?; - } + while let Some(se) = iter.next() { + if match &mut se.resource_or_table { + ResourceOrTable::Resource(resource) => { + resource.write_from_data_end(writer, &(), start_after_data) + } + ResourceOrTable::Table(table) => table + .write_from_data_end(writer, &(), start_after_data) + .map(|()| true), + }? { + table_found = true; + for info in se.infos.iter_mut() { + info.write(writer, context)?; } + break; } } - for se in iter { - se.write(writer)?; - } if table_found { + for se in iter { + se.write(writer)?; + } // Close tag writer .write_event(Event::End(tag.to_end()))