xso-proc: Replace std stuff with alloc/core stuff

This commit is contained in:
xmppftw xmppftw 2024-12-19 19:56:17 +01:00 committed by Emmanuel Gil Peyrot
commit 4e5f0bc961
8 changed files with 12 additions and 8 deletions

View file

@ -140,7 +140,7 @@ impl NameVariant {
quote! { quote! {
let name = ( let name = (
::xso::exports::rxml::Namespace::from(#xml_namespace), ::xso::exports::rxml::Namespace::from(#xml_namespace),
::std::borrow::Cow::Borrowed(#xml_name), ::alloc::borrow::Cow::Borrowed(#xml_name),
); );
#init #init
} }

View file

@ -102,7 +102,7 @@ impl Field for AttributeField {
generator: quote! { generator: quote! {
#as_optional_xml_text(#bound_name)?.map(|#bound_name| ::xso::Item::Attribute( #as_optional_xml_text(#bound_name)?.map(|#bound_name| ::xso::Item::Attribute(
#xml_namespace, #xml_namespace,
::std::borrow::Cow::Borrowed(#xml_name), ::alloc::borrow::Cow::Borrowed(#xml_name),
#bound_name, #bound_name,
)); ));
}, },

View file

@ -423,7 +423,7 @@ impl ExtractDef {
quote! { quote! {
let name = ( let name = (
::xso::exports::rxml::Namespace::from(#xml_namespace), ::xso::exports::rxml::Namespace::from(#xml_namespace),
::std::borrow::Cow::Borrowed(#xml_name), ::alloc::borrow::Cow::Borrowed(#xml_name),
); );
#init #init
} }

View file

@ -51,7 +51,7 @@ impl Field for TextField {
Ok(FieldBuilderPart::Text { Ok(FieldBuilderPart::Text {
value: FieldTempInit { value: FieldTempInit {
init: quote! { ::std::string::String::new() }, init: quote! { ::alloc::string::String::new() },
ty: string_ty(Span::call_site()), ty: string_ty(Span::call_site()),
}, },
collect: quote! { collect: quote! {

View file

@ -18,6 +18,8 @@ return to `xso` for more information**. The documentation of
**You have been warned.** **You have been warned.**
*/ */
extern crate alloc;
// Wondering about RawTokenStream vs. TokenStream? // Wondering about RawTokenStream vs. TokenStream?
// syn mostly works with proc_macro2, while the proc macros themselves use // syn mostly works with proc_macro2, while the proc macros themselves use
// proc_macro. // proc_macro.

View file

@ -294,7 +294,7 @@ impl StructInner {
quote! { quote! {
let name = ( let name = (
::xso::exports::rxml::Namespace::from(#xml_namespace), ::xso::exports::rxml::Namespace::from(#xml_namespace),
::std::borrow::Cow::Borrowed(#xml_name), ::alloc::borrow::Cow::Borrowed(#xml_name),
); );
#init #init
} }

View file

@ -84,7 +84,7 @@ pub(crate) fn cow_ty(ty: Type, lifetime: Lifetime) -> Type {
}), }),
segments: [ segments: [
PathSegment { PathSegment {
ident: Ident::new("std", span), ident: Ident::new("alloc", span),
arguments: PathArguments::None, arguments: PathArguments::None,
}, },
PathSegment { PathSegment {
@ -233,7 +233,7 @@ pub(crate) fn default_fn(of_ty: Type) -> Expr {
}) })
} }
/// Construct a [`syn::Type`] referring to `::std::string::String`. /// Construct a [`syn::Type`] referring to `::alloc::string::String`.
pub(crate) fn string_ty(span: Span) -> Type { pub(crate) fn string_ty(span: Span) -> Type {
Type::Path(TypePath { Type::Path(TypePath {
qself: None, qself: None,
@ -243,7 +243,7 @@ pub(crate) fn string_ty(span: Span) -> Type {
}), }),
segments: [ segments: [
PathSegment { PathSegment {
ident: Ident::new("std", span), ident: Ident::new("alloc", span),
arguments: PathArguments::None, arguments: PathArguments::None,
}, },
PathSegment { PathSegment {

View file

@ -588,6 +588,7 @@ a field, for consistency.
#### Example without codec #### Example without codec
```rust ```rust
# extern crate alloc;
# use xso::FromXml; # use xso::FromXml;
#[derive(FromXml, Debug, PartialEq)] #[derive(FromXml, Debug, PartialEq)]
#[xml(namespace = "urn:example", name = "foo")] #[xml(namespace = "urn:example", name = "foo")]
@ -605,6 +606,7 @@ assert_eq!(foo, Foo {
#### Example with codec #### Example with codec
```rust ```rust
# extern crate alloc;
# use xso::FromXml; # use xso::FromXml;
#[derive(FromXml, Debug, PartialEq)] #[derive(FromXml, Debug, PartialEq)]
#[xml(namespace = "urn:example", name = "foo")] #[xml(namespace = "urn:example", name = "foo")]