From 4e5f0bc9615f075f1bd2094f200cdc5e37ea1976 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Thu, 19 Dec 2024 19:56:17 +0100 Subject: [PATCH] xso-proc: Replace std stuff with alloc/core stuff --- xso-proc/src/enums.rs | 2 +- xso-proc/src/field/attribute.rs | 2 +- xso-proc/src/field/child.rs | 2 +- xso-proc/src/field/text.rs | 2 +- xso-proc/src/lib.rs | 2 ++ xso-proc/src/structs.rs | 2 +- xso-proc/src/types.rs | 6 +++--- xso/src/from_xml_doc.md | 2 ++ 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/xso-proc/src/enums.rs b/xso-proc/src/enums.rs index 54dcef9502ee32ae15802e09cc90c7ca45d0ce1b..d42f28d362ccca893c6856d6a1c417dd4de486bc 100644 --- a/xso-proc/src/enums.rs +++ b/xso-proc/src/enums.rs @@ -140,7 +140,7 @@ impl NameVariant { quote! { let name = ( ::xso::exports::rxml::Namespace::from(#xml_namespace), - ::std::borrow::Cow::Borrowed(#xml_name), + ::alloc::borrow::Cow::Borrowed(#xml_name), ); #init } diff --git a/xso-proc/src/field/attribute.rs b/xso-proc/src/field/attribute.rs index 950d9d6c2d767ee79999fba3e4d6d6bb7602a2e9..f358e11986a40b07328d167b29514749868029b4 100644 --- a/xso-proc/src/field/attribute.rs +++ b/xso-proc/src/field/attribute.rs @@ -102,7 +102,7 @@ impl Field for AttributeField { generator: quote! { #as_optional_xml_text(#bound_name)?.map(|#bound_name| ::xso::Item::Attribute( #xml_namespace, - ::std::borrow::Cow::Borrowed(#xml_name), + ::alloc::borrow::Cow::Borrowed(#xml_name), #bound_name, )); }, diff --git a/xso-proc/src/field/child.rs b/xso-proc/src/field/child.rs index c64792902a9035e4d56cfafa1535b30186617686..bbfcda8424c52a2fb94c8f1d3abafb00c982f4a7 100644 --- a/xso-proc/src/field/child.rs +++ b/xso-proc/src/field/child.rs @@ -423,7 +423,7 @@ impl ExtractDef { quote! { let name = ( ::xso::exports::rxml::Namespace::from(#xml_namespace), - ::std::borrow::Cow::Borrowed(#xml_name), + ::alloc::borrow::Cow::Borrowed(#xml_name), ); #init } diff --git a/xso-proc/src/field/text.rs b/xso-proc/src/field/text.rs index 9e14d0ad482612b90b2dd78663554b1b69461f8d..dab480a2b039dc6cd4beed32dd43d3668406d5ae 100644 --- a/xso-proc/src/field/text.rs +++ b/xso-proc/src/field/text.rs @@ -51,7 +51,7 @@ impl Field for TextField { Ok(FieldBuilderPart::Text { value: FieldTempInit { - init: quote! { ::std::string::String::new() }, + init: quote! { ::alloc::string::String::new() }, ty: string_ty(Span::call_site()), }, collect: quote! { diff --git a/xso-proc/src/lib.rs b/xso-proc/src/lib.rs index deff73e1181ebff89facc1e2251e726d0159ec15..e2fc530cadeda79fa7f98bab27aead5bf9b3d9ab 100644 --- a/xso-proc/src/lib.rs +++ b/xso-proc/src/lib.rs @@ -18,6 +18,8 @@ return to `xso` for more information**. The documentation of **You have been warned.** */ +extern crate alloc; + // Wondering about RawTokenStream vs. TokenStream? // syn mostly works with proc_macro2, while the proc macros themselves use // proc_macro. diff --git a/xso-proc/src/structs.rs b/xso-proc/src/structs.rs index e6ce621cd077fbf6956922b64b7d9cf55c771db0..2ab2fededf385f9200af1d1fc25d7cdf815b1341 100644 --- a/xso-proc/src/structs.rs +++ b/xso-proc/src/structs.rs @@ -294,7 +294,7 @@ impl StructInner { quote! { let name = ( ::xso::exports::rxml::Namespace::from(#xml_namespace), - ::std::borrow::Cow::Borrowed(#xml_name), + ::alloc::borrow::Cow::Borrowed(#xml_name), ); #init } diff --git a/xso-proc/src/types.rs b/xso-proc/src/types.rs index 2392a22c11ce9018cc2d1f82868965f4354bdb22..dbb17717a3094d0ff0f5143310eefe8b74a60745 100644 --- a/xso-proc/src/types.rs +++ b/xso-proc/src/types.rs @@ -84,7 +84,7 @@ pub(crate) fn cow_ty(ty: Type, lifetime: Lifetime) -> Type { }), segments: [ PathSegment { - ident: Ident::new("std", span), + ident: Ident::new("alloc", span), arguments: PathArguments::None, }, 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 { Type::Path(TypePath { qself: None, @@ -243,7 +243,7 @@ pub(crate) fn string_ty(span: Span) -> Type { }), segments: [ PathSegment { - ident: Ident::new("std", span), + ident: Ident::new("alloc", span), arguments: PathArguments::None, }, PathSegment { diff --git a/xso/src/from_xml_doc.md b/xso/src/from_xml_doc.md index ecf0a1f3b5966b6d2129fefec774ac57b99c75a5..12b94e44c1f980b279914328c1de7477fd6f8f54 100644 --- a/xso/src/from_xml_doc.md +++ b/xso/src/from_xml_doc.md @@ -588,6 +588,7 @@ a field, for consistency. #### Example without codec ```rust +# extern crate alloc; # use xso::FromXml; #[derive(FromXml, Debug, PartialEq)] #[xml(namespace = "urn:example", name = "foo")] @@ -605,6 +606,7 @@ assert_eq!(foo, Foo { #### Example with codec ```rust +# extern crate alloc; # use xso::FromXml; #[derive(FromXml, Debug, PartialEq)] #[xml(namespace = "urn:example", name = "foo")]