xso-proc: merge extract and normal child code
This commit is contained in:
parent
7ab375fad7
commit
5590d707fb
1 changed files with 226 additions and 237 deletions
|
|
@ -140,6 +140,26 @@ pub(crate) enum FieldIteratorPart {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Definition of what to extract from a child element.
|
||||||
|
struct ExtractDef {
|
||||||
|
/// The XML namespace of the child to extract data from.
|
||||||
|
xml_namespace: NamespaceRef,
|
||||||
|
|
||||||
|
/// The XML name of the child to extract data from.
|
||||||
|
xml_name: NameRef,
|
||||||
|
|
||||||
|
/// Compound which contains the arguments of the `extract(..)` meta
|
||||||
|
/// (except the `from`), transformed into a struct with unnamed
|
||||||
|
/// fields.
|
||||||
|
///
|
||||||
|
/// This is used to generate the parsing/serialisation code, by
|
||||||
|
/// essentially "declaring" a shim struct, as if it were a real Rust
|
||||||
|
/// struct, and using the result of the parsing process directly for
|
||||||
|
/// the field on which the `extract(..)` option was used, instead of
|
||||||
|
/// putting it into a Rust struct.
|
||||||
|
parts: Compound,
|
||||||
|
}
|
||||||
|
|
||||||
/// Specify how the field is mapped to XML.
|
/// Specify how the field is mapped to XML.
|
||||||
enum FieldKind {
|
enum FieldKind {
|
||||||
/// The field maps to an attribute.
|
/// The field maps to an attribute.
|
||||||
|
|
@ -169,26 +189,10 @@ enum FieldKind {
|
||||||
|
|
||||||
/// Number of child elements allowed.
|
/// Number of child elements allowed.
|
||||||
amount: AmountConstraint,
|
amount: AmountConstraint,
|
||||||
},
|
|
||||||
|
|
||||||
/// Extract contents from a child element.
|
/// If set, the child element is not parsed as a field implementing
|
||||||
Extract {
|
/// `FromXml` / `AsXml`, but instead its contents are extracted.
|
||||||
/// The XML namespace of the child to extract data from.
|
extract: Option<ExtractDef>,
|
||||||
xml_namespace: NamespaceRef,
|
|
||||||
|
|
||||||
/// The XML name of the child to extract data from.
|
|
||||||
xml_name: NameRef,
|
|
||||||
|
|
||||||
/// Compound which contains the arguments of the `extract(..)` meta
|
|
||||||
/// (except the `from`), transformed into a struct with unnamed
|
|
||||||
/// fields.
|
|
||||||
///
|
|
||||||
/// This is used to generate the parsing/serialisation code, by
|
|
||||||
/// essentially "declaring" a shim struct, as if it were a real Rust
|
|
||||||
/// struct, and using the result of the parsing process directly for
|
|
||||||
/// the field on which the `extract(..)` option was used, instead of
|
|
||||||
/// putting it into a Rust struct.
|
|
||||||
parts: Compound,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,6 +273,7 @@ impl FieldKind {
|
||||||
Ok(Self::Child {
|
Ok(Self::Child {
|
||||||
default_,
|
default_,
|
||||||
amount: amount.unwrap_or(AmountConstraint::FixedSingle(Span::call_site())),
|
amount: amount.unwrap_or(AmountConstraint::FixedSingle(Span::call_site())),
|
||||||
|
extract: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -303,10 +308,14 @@ impl FieldKind {
|
||||||
[FieldDef::from_extract(field, 0, field_ty, &xml_namespace)].into_iter(),
|
[FieldDef::from_extract(field, 0, field_ty, &xml_namespace)].into_iter(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Self::Extract {
|
Ok(Self::Child {
|
||||||
|
default_: Flag::Absent,
|
||||||
|
amount: AmountConstraint::FixedSingle(Span::call_site()),
|
||||||
|
extract: Some(ExtractDef {
|
||||||
xml_namespace,
|
xml_namespace,
|
||||||
xml_name,
|
xml_name,
|
||||||
parts,
|
parts,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -475,6 +484,7 @@ impl FieldDef {
|
||||||
FieldKind::Child {
|
FieldKind::Child {
|
||||||
ref default_,
|
ref default_,
|
||||||
ref amount,
|
ref amount,
|
||||||
|
ref extract,
|
||||||
} => {
|
} => {
|
||||||
let FromEventsScope {
|
let FromEventsScope {
|
||||||
ref substate_result,
|
ref substate_result,
|
||||||
|
|
@ -487,100 +497,16 @@ impl FieldDef {
|
||||||
AmountConstraint::Any(_) => into_iterator_item_ty(self.ty.clone()),
|
AmountConstraint::Any(_) => into_iterator_item_ty(self.ty.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let from_events = from_events_fn(element_ty.clone());
|
let (extra_defs, matcher, fetch, builder) = match extract {
|
||||||
let from_xml_builder = from_xml_builder_ty(element_ty.clone());
|
Some(ExtractDef {
|
||||||
|
|
||||||
let matcher = quote! { #from_events(name, attrs) };
|
|
||||||
let builder = from_xml_builder;
|
|
||||||
|
|
||||||
match amount {
|
|
||||||
AmountConstraint::FixedSingle(_) => {
|
|
||||||
let missing_msg =
|
|
||||||
error_message::on_missing_child(container_name, &self.member);
|
|
||||||
let duplicate_msg =
|
|
||||||
error_message::on_duplicate_child(container_name, &self.member);
|
|
||||||
|
|
||||||
let on_absent = match default_ {
|
|
||||||
Flag::Absent => quote! {
|
|
||||||
return ::core::result::Result::Err(::xso::error::Error::Other(#missing_msg).into())
|
|
||||||
},
|
|
||||||
Flag::Present(_) => {
|
|
||||||
let default_ = default_fn(self.ty.clone());
|
|
||||||
quote! {
|
|
||||||
#default_()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(FieldBuilderPart::Nested {
|
|
||||||
extra_defs: TokenStream::default(),
|
|
||||||
value: FieldTempInit {
|
|
||||||
init: quote! { ::std::option::Option::None },
|
|
||||||
ty: option_ty(self.ty.clone()),
|
|
||||||
},
|
|
||||||
matcher: quote! {
|
|
||||||
match #matcher {
|
|
||||||
::core::result::Result::Ok(v) => if #field_access.is_some() {
|
|
||||||
::core::result::Result::Err(::xso::error::FromEventsError::Invalid(::xso::error::Error::Other(#duplicate_msg)))
|
|
||||||
} else {
|
|
||||||
::core::result::Result::Ok(v)
|
|
||||||
},
|
|
||||||
::core::result::Result::Err(e) => ::core::result::Result::Err(e),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
builder,
|
|
||||||
collect: quote! {
|
|
||||||
#field_access = ::std::option::Option::Some(#substate_result);
|
|
||||||
},
|
|
||||||
finalize: quote! {
|
|
||||||
match #field_access {
|
|
||||||
::std::option::Option::Some(value) => value,
|
|
||||||
::std::option::Option::None => #on_absent,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
AmountConstraint::Any(_) => {
|
|
||||||
let ty_extend = extend_fn(self.ty.clone(), element_ty.clone());
|
|
||||||
let ty_default = default_fn(self.ty.clone());
|
|
||||||
Ok(FieldBuilderPart::Nested {
|
|
||||||
extra_defs: TokenStream::default(),
|
|
||||||
value: FieldTempInit {
|
|
||||||
init: quote! { #ty_default() },
|
|
||||||
ty: self.ty.clone(),
|
|
||||||
},
|
|
||||||
matcher,
|
|
||||||
builder,
|
|
||||||
collect: quote! {
|
|
||||||
#ty_extend(&mut #field_access, [#substate_result]);
|
|
||||||
},
|
|
||||||
finalize: quote! { #field_access },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FieldKind::Extract {
|
|
||||||
ref xml_namespace,
|
ref xml_namespace,
|
||||||
ref xml_name,
|
ref xml_name,
|
||||||
ref parts,
|
ref parts,
|
||||||
} => {
|
}) => {
|
||||||
let FromEventsScope {
|
|
||||||
ref substate_result,
|
|
||||||
..
|
|
||||||
} = scope;
|
|
||||||
let field_access = scope.access_field(&self.member);
|
|
||||||
|
|
||||||
let missing_msg = error_message::on_missing_child(container_name, &self.member);
|
|
||||||
let duplicate_msg = error_message::on_duplicate_child(container_name, &self.member);
|
|
||||||
|
|
||||||
let on_absent = quote! {
|
|
||||||
return ::core::result::Result::Err(::xso::error::Error::Other(#missing_msg).into())
|
|
||||||
};
|
|
||||||
|
|
||||||
let from_xml_builder_ty_ident =
|
let from_xml_builder_ty_ident =
|
||||||
scope.make_member_type_name(&self.member, "FromXmlBuilder");
|
scope.make_member_type_name(&self.member, "FromXmlBuilder");
|
||||||
let state_ty_ident = quote::format_ident!("{}State", from_xml_builder_ty_ident,);
|
let state_ty_ident =
|
||||||
|
quote::format_ident!("{}State", from_xml_builder_ty_ident,);
|
||||||
|
|
||||||
let extra_defs = parts.make_from_events_statemachine(
|
let extra_defs = parts.make_from_events_statemachine(
|
||||||
&state_ty_ident,
|
&state_ty_ident,
|
||||||
|
|
@ -599,11 +525,56 @@ impl FieldDef {
|
||||||
&Type::Tuple(TypeTuple {
|
&Type::Tuple(TypeTuple {
|
||||||
paren_token: token::Paren::default(),
|
paren_token: token::Paren::default(),
|
||||||
elems: [
|
elems: [
|
||||||
self.ty.clone(),
|
element_ty.clone(),
|
||||||
].into_iter().collect(),
|
].into_iter().collect(),
|
||||||
})
|
})
|
||||||
)?;
|
)?;
|
||||||
let from_xml_builder_ty = ty_from_ident(from_xml_builder_ty_ident.clone()).into();
|
let from_xml_builder_ty =
|
||||||
|
ty_from_ident(from_xml_builder_ty_ident.clone()).into();
|
||||||
|
|
||||||
|
let matcher = quote! { #state_ty_ident::new(name, attrs).map(|x| #from_xml_builder_ty_ident(::core::option::Option::Some(x))) };
|
||||||
|
|
||||||
|
(
|
||||||
|
extra_defs,
|
||||||
|
matcher,
|
||||||
|
quote! { #substate_result.0 },
|
||||||
|
from_xml_builder_ty,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let from_events = from_events_fn(element_ty.clone());
|
||||||
|
let from_xml_builder = from_xml_builder_ty(element_ty.clone());
|
||||||
|
|
||||||
|
let matcher = quote! { #from_events(name, attrs) };
|
||||||
|
let builder = from_xml_builder;
|
||||||
|
|
||||||
|
(
|
||||||
|
TokenStream::default(),
|
||||||
|
matcher,
|
||||||
|
quote! { #substate_result },
|
||||||
|
builder,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match amount {
|
||||||
|
AmountConstraint::FixedSingle(_) => {
|
||||||
|
let missing_msg =
|
||||||
|
error_message::on_missing_child(container_name, &self.member);
|
||||||
|
let duplicate_msg =
|
||||||
|
error_message::on_duplicate_child(container_name, &self.member);
|
||||||
|
|
||||||
|
let on_absent = match default_ {
|
||||||
|
Flag::Absent => quote! {
|
||||||
|
return ::core::result::Result::Err(::xso::error::Error::Other(#missing_msg).into())
|
||||||
|
},
|
||||||
|
Flag::Present(_) => {
|
||||||
|
let default_ = default_fn(element_ty.clone());
|
||||||
|
quote! {
|
||||||
|
#default_()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Ok(FieldBuilderPart::Nested {
|
Ok(FieldBuilderPart::Nested {
|
||||||
extra_defs,
|
extra_defs,
|
||||||
|
|
@ -612,18 +583,18 @@ impl FieldDef {
|
||||||
ty: option_ty(self.ty.clone()),
|
ty: option_ty(self.ty.clone()),
|
||||||
},
|
},
|
||||||
matcher: quote! {
|
matcher: quote! {
|
||||||
match #state_ty_ident::new(name, attrs) {
|
match #matcher {
|
||||||
::core::result::Result::Ok(v) => if #field_access.is_some() {
|
::core::result::Result::Ok(v) => if #field_access.is_some() {
|
||||||
::core::result::Result::Err(::xso::error::FromEventsError::Invalid(::xso::error::Error::Other(#duplicate_msg)))
|
::core::result::Result::Err(::xso::error::FromEventsError::Invalid(::xso::error::Error::Other(#duplicate_msg)))
|
||||||
} else {
|
} else {
|
||||||
::core::result::Result::Ok(#from_xml_builder_ty_ident(::core::option::Option::Some(v)))
|
::core::result::Result::Ok(v)
|
||||||
},
|
},
|
||||||
::core::result::Result::Err(e) => ::core::result::Result::Err(e),
|
::core::result::Result::Err(e) => ::core::result::Result::Err(e),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: from_xml_builder_ty,
|
builder,
|
||||||
collect: quote! {
|
collect: quote! {
|
||||||
#field_access = ::std::option::Option::Some(#substate_result.0);
|
#field_access = ::std::option::Option::Some(#fetch);
|
||||||
},
|
},
|
||||||
finalize: quote! {
|
finalize: quote! {
|
||||||
match #field_access {
|
match #field_access {
|
||||||
|
|
@ -633,6 +604,25 @@ impl FieldDef {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
AmountConstraint::Any(_) => {
|
||||||
|
let ty_extend = extend_fn(self.ty.clone(), element_ty.clone());
|
||||||
|
let ty_default = default_fn(self.ty.clone());
|
||||||
|
Ok(FieldBuilderPart::Nested {
|
||||||
|
extra_defs,
|
||||||
|
value: FieldTempInit {
|
||||||
|
init: quote! { #ty_default() },
|
||||||
|
ty: self.ty.clone(),
|
||||||
|
},
|
||||||
|
matcher,
|
||||||
|
builder,
|
||||||
|
collect: quote! {
|
||||||
|
#ty_extend(&mut #field_access, [#fetch]);
|
||||||
|
},
|
||||||
|
finalize: quote! { #field_access },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -689,92 +679,28 @@ impl FieldDef {
|
||||||
|
|
||||||
FieldKind::Child {
|
FieldKind::Child {
|
||||||
default_: _,
|
default_: _,
|
||||||
amount: AmountConstraint::FixedSingle(_),
|
ref amount,
|
||||||
} => {
|
ref extract,
|
||||||
let AsItemsScope { ref lifetime, .. } = scope;
|
|
||||||
|
|
||||||
let as_xml_iter = as_xml_iter_fn(self.ty.clone());
|
|
||||||
let item_iter = item_iter_ty(self.ty.clone(), lifetime.clone());
|
|
||||||
|
|
||||||
Ok(FieldIteratorPart::Content {
|
|
||||||
extra_defs: TokenStream::default(),
|
|
||||||
value: FieldTempInit {
|
|
||||||
init: quote! {
|
|
||||||
#as_xml_iter(#bound_name)?
|
|
||||||
},
|
|
||||||
ty: item_iter,
|
|
||||||
},
|
|
||||||
generator: quote! {
|
|
||||||
#bound_name.next().transpose()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
FieldKind::Child {
|
|
||||||
default_: _,
|
|
||||||
amount: AmountConstraint::Any(_),
|
|
||||||
} => {
|
} => {
|
||||||
let AsItemsScope { ref lifetime, .. } = scope;
|
let AsItemsScope { ref lifetime, .. } = scope;
|
||||||
|
|
||||||
|
let item_ty = match amount {
|
||||||
|
AmountConstraint::FixedSingle(_) => self.ty.clone(),
|
||||||
|
AmountConstraint::Any(_) => {
|
||||||
// This should give us the type of element stored in the
|
// This should give us the type of element stored in the
|
||||||
// collection.
|
// collection.
|
||||||
let element_ty = into_iterator_item_ty(self.ty.clone());
|
into_iterator_item_ty(self.ty.clone())
|
||||||
|
|
||||||
// And this is the collection type we actually work with --
|
|
||||||
// as_xml_iter uses references after all.
|
|
||||||
let ty = ref_ty(self.ty.clone(), lifetime.clone());
|
|
||||||
|
|
||||||
// as_xml_iter is called on the bare type (not the ref type)
|
|
||||||
let as_xml_iter = as_xml_iter_fn(element_ty.clone());
|
|
||||||
|
|
||||||
// And thus the iterator associated with AsXml is also derived
|
|
||||||
// from the bare type.
|
|
||||||
let item_iter = item_iter_ty(element_ty.clone(), lifetime.clone());
|
|
||||||
|
|
||||||
// But the iterator for iterating over the elements inside the
|
|
||||||
// collection must use the ref type.
|
|
||||||
let element_iter = into_iterator_iter_ty(ty.clone());
|
|
||||||
|
|
||||||
// And likewise the into_iter impl.
|
|
||||||
let into_iter = into_iterator_into_iter_fn(ty.clone());
|
|
||||||
|
|
||||||
let state_ty = Type::Tuple(TypeTuple {
|
|
||||||
paren_token: token::Paren::default(),
|
|
||||||
elems: [element_iter, option_ty(item_iter)].into_iter().collect(),
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(FieldIteratorPart::Content {
|
|
||||||
extra_defs: TokenStream::default(),
|
|
||||||
value: FieldTempInit {
|
|
||||||
init: quote! {
|
|
||||||
(#into_iter(#bound_name), ::core::option::Option::None)
|
|
||||||
},
|
|
||||||
ty: state_ty,
|
|
||||||
},
|
|
||||||
generator: quote! {
|
|
||||||
loop {
|
|
||||||
if let ::core::option::Option::Some(current) = #bound_name.1.as_mut() {
|
|
||||||
if let ::core::option::Option::Some(item) = current.next() {
|
|
||||||
break ::core::option::Option::Some(item).transpose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let ::core::option::Option::Some(item) = #bound_name.0.next() {
|
|
||||||
#bound_name.1 = ::core::option::Option::Some(#as_xml_iter(item)?)
|
|
||||||
} else {
|
|
||||||
break ::core::result::Result::Ok(::core::option::Option::None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
FieldKind::Extract {
|
let (extra_defs, fetch, as_xml_iter, iter_ty) = match extract {
|
||||||
|
Some(ExtractDef {
|
||||||
ref xml_namespace,
|
ref xml_namespace,
|
||||||
ref xml_name,
|
ref xml_name,
|
||||||
ref parts,
|
ref parts,
|
||||||
} => {
|
}) => {
|
||||||
let AsItemsScope { ref lifetime, .. } = scope;
|
let item_iter_ty_ident =
|
||||||
let item_iter_ty_ident = scope.make_member_type_name(&self.member, "AsXmlIterator");
|
scope.make_member_type_name(&self.member, "AsXmlIterator");
|
||||||
let state_ty_ident = quote::format_ident!("{}State", item_iter_ty_ident,);
|
let state_ty_ident = quote::format_ident!("{}State", item_iter_ty_ident,);
|
||||||
let mut item_iter_ty = ty_from_ident(item_iter_ty_ident.clone());
|
let mut item_iter_ty = ty_from_ident(item_iter_ty_ident.clone());
|
||||||
item_iter_ty.path.segments[0].arguments =
|
item_iter_ty.path.segments[0].arguments =
|
||||||
|
|
@ -809,7 +735,7 @@ impl FieldDef {
|
||||||
&Visibility::Inherited,
|
&Visibility::Inherited,
|
||||||
&Type::Tuple(TypeTuple {
|
&Type::Tuple(TypeTuple {
|
||||||
paren_token: token::Paren::default(),
|
paren_token: token::Paren::default(),
|
||||||
elems: [ref_ty(self.ty.clone(), lifetime.clone())]
|
elems: [ref_ty(item_ty.clone(), lifetime.clone())]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
}),
|
}),
|
||||||
|
|
@ -818,21 +744,84 @@ impl FieldDef {
|
||||||
&item_iter_ty,
|
&item_iter_ty,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(FieldIteratorPart::Content {
|
(
|
||||||
|
extra_defs,
|
||||||
|
quote! { (&#bound_name,) },
|
||||||
|
quote! { #item_iter_ty_ident::new },
|
||||||
|
item_iter_ty,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let as_xml_iter = as_xml_iter_fn(item_ty.clone());
|
||||||
|
let item_iter = item_iter_ty(item_ty.clone(), lifetime.clone());
|
||||||
|
|
||||||
|
(
|
||||||
|
TokenStream::default(),
|
||||||
|
quote! { #bound_name },
|
||||||
|
quote! { #as_xml_iter },
|
||||||
|
item_iter,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match amount {
|
||||||
|
AmountConstraint::FixedSingle(_) => Ok(FieldIteratorPart::Content {
|
||||||
extra_defs,
|
extra_defs,
|
||||||
value: FieldTempInit {
|
value: FieldTempInit {
|
||||||
init: quote! {
|
init: quote! {
|
||||||
#item_iter_ty_ident::new((&#bound_name,))?
|
#as_xml_iter(#fetch)?
|
||||||
},
|
},
|
||||||
ty: item_iter_ty,
|
ty: iter_ty,
|
||||||
},
|
},
|
||||||
generator: quote! {
|
generator: quote! {
|
||||||
#bound_name.next().transpose()
|
#bound_name.next().transpose()
|
||||||
},
|
},
|
||||||
|
}),
|
||||||
|
AmountConstraint::Any(_) => {
|
||||||
|
// This is the collection type we actually work
|
||||||
|
// with -- as_xml_iter uses references after all.
|
||||||
|
let ty = ref_ty(self.ty.clone(), lifetime.clone());
|
||||||
|
|
||||||
|
// But the iterator for iterating over the elements
|
||||||
|
// inside the collection must use the ref type.
|
||||||
|
let element_iter = into_iterator_iter_ty(ty.clone());
|
||||||
|
|
||||||
|
// And likewise the into_iter impl.
|
||||||
|
let into_iter = into_iterator_into_iter_fn(ty.clone());
|
||||||
|
|
||||||
|
let state_ty = Type::Tuple(TypeTuple {
|
||||||
|
paren_token: token::Paren::default(),
|
||||||
|
elems: [element_iter, option_ty(iter_ty)].into_iter().collect(),
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(FieldIteratorPart::Content {
|
||||||
|
extra_defs,
|
||||||
|
value: FieldTempInit {
|
||||||
|
init: quote! {
|
||||||
|
(#into_iter(#bound_name), ::core::option::Option::None)
|
||||||
|
},
|
||||||
|
ty: state_ty,
|
||||||
|
},
|
||||||
|
generator: quote! {
|
||||||
|
loop {
|
||||||
|
if let ::core::option::Option::Some(current) = #bound_name.1.as_mut() {
|
||||||
|
if let ::core::option::Option::Some(item) = current.next() {
|
||||||
|
break ::core::option::Option::Some(item).transpose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let ::core::option::Option::Some(item) = #bound_name.0.next() {
|
||||||
|
#bound_name.1 = ::core::option::Option::Some(#as_xml_iter({ let #bound_name = item; #fetch })?)
|
||||||
|
} else {
|
||||||
|
break ::core::result::Result::Ok(::core::option::Option::None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return true if this field's parsing consumes text data.
|
/// Return true if this field's parsing consumes text data.
|
||||||
pub(crate) fn is_text_field(&self) -> bool {
|
pub(crate) fn is_text_field(&self) -> bool {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue