xso: only take reference in transform

This avoids the need for an expensive clone. Since we switched to AsXml
instead of IntoXml, we don't necessarily have to clone the data when
building new elements, only when it's absolutely necessary. The clones
then happen implicitly in the ItemToEvent iterator used internally.

This mostly fixes #86, with the caveat that there's no absolutely cheap
test: On success, the entire element will be copied, while on failure,
you learn about it rather quickly.
This commit is contained in:
Jonas Schäfer 2024-12-20 12:43:23 +01:00
commit 58698f633f
4 changed files with 16 additions and 4 deletions

View file

@ -152,6 +152,12 @@ fn as_xml_impl(input: Item) -> Result<TokenStream> {
result.extend(quote! {
impl ::core::convert::From<#ident> for ::xso::exports::minidom::Element {
fn from(other: #ident) -> Self {
::xso::transform(&other).expect("seamless conversion into minidom::Element")
}
}
impl ::core::convert::From<&#ident> for ::xso::exports::minidom::Element {
fn from(other: &#ident) -> Self {
::xso::transform(other).expect("seamless conversion into minidom::Element")
}
}
@ -163,6 +169,13 @@ fn as_xml_impl(input: Item) -> Result<TokenStream> {
type Error = ::xso::error::Error;
fn try_from(other: #ident) -> ::core::result::Result<Self, Self::Error> {
::xso::transform(&other)
}
}
impl ::core::convert::TryFrom<&#ident> for ::xso::exports::minidom::Element {
type Error = ::xso::error::Error;
fn try_from(other: &#ident) -> ::core::result::Result<Self, Self::Error> {
::xso::transform(other)
}
}