xso-proc: Use core instead of std wherever possible
This commit is contained in:
parent
5de1891f06
commit
1828fde78c
7 changed files with 43 additions and 43 deletions
|
|
@ -161,7 +161,7 @@ impl Compound {
|
||||||
});
|
});
|
||||||
text_handler = Some(quote! {
|
text_handler = Some(quote! {
|
||||||
#collect
|
#collect
|
||||||
::core::result::Result::Ok(::std::ops::ControlFlow::Break(
|
::core::result::Result::Ok(::core::ops::ControlFlow::Break(
|
||||||
Self::#default_state_ident { #builder_data_ident }
|
Self::#default_state_ident { #builder_data_ident }
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
|
@ -196,14 +196,14 @@ impl Compound {
|
||||||
&builder,
|
&builder,
|
||||||
).with_mut(substate_data).with_impl(quote! {
|
).with_mut(substate_data).with_impl(quote! {
|
||||||
match #feed(&mut #substate_data, ev)? {
|
match #feed(&mut #substate_data, ev)? {
|
||||||
::std::option::Option::Some(#substate_result) => {
|
::core::option::Option::Some(#substate_result) => {
|
||||||
#collect
|
#collect
|
||||||
::std::result::Result::Ok(::std::ops::ControlFlow::Break(Self::#default_state_ident {
|
::core::result::Result::Ok(::core::ops::ControlFlow::Break(Self::#default_state_ident {
|
||||||
#builder_data_ident,
|
#builder_data_ident,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
::std::option::Option::None => {
|
::core::option::Option::None => {
|
||||||
::std::result::Result::Ok(::std::ops::ControlFlow::Break(Self::#state_name {
|
::core::result::Result::Ok(::core::ops::ControlFlow::Break(Self::#state_name {
|
||||||
#builder_data_ident,
|
#builder_data_ident,
|
||||||
#substate_data,
|
#substate_data,
|
||||||
}))
|
}))
|
||||||
|
|
@ -221,10 +221,10 @@ impl Compound {
|
||||||
|
|
||||||
child_matchers.extend(quote! {
|
child_matchers.extend(quote! {
|
||||||
let (name, attrs) = match #matcher {
|
let (name, attrs) = match #matcher {
|
||||||
::std::result::Result::Err(::xso::error::FromEventsError::Mismatch { name, attrs }) => (name, attrs),
|
::core::result::Result::Err(::xso::error::FromEventsError::Mismatch { name, attrs }) => (name, attrs),
|
||||||
::std::result::Result::Err(::xso::error::FromEventsError::Invalid(e)) => return ::std::result::Result::Err(e),
|
::core::result::Result::Err(::xso::error::FromEventsError::Invalid(e)) => return ::core::result::Result::Err(e),
|
||||||
::std::result::Result::Ok(#substate_data) => {
|
::core::result::Result::Ok(#substate_data) => {
|
||||||
return ::std::result::Result::Ok(::std::ops::ControlFlow::Break(Self::#state_name {
|
return ::core::result::Result::Ok(::core::ops::ControlFlow::Break(Self::#state_name {
|
||||||
#builder_data_ident,
|
#builder_data_ident,
|
||||||
#substate_data,
|
#substate_data,
|
||||||
}))
|
}))
|
||||||
|
|
@ -255,7 +255,7 @@ impl Compound {
|
||||||
if #text.as_bytes().iter().any(|b| *b != b' ' && *b != b'\t' && *b != b'\r' && *b != b'\n') {
|
if #text.as_bytes().iter().any(|b| *b != b' ' && *b != b'\t' && *b != b'\r' && *b != b'\n') {
|
||||||
::core::result::Result::Err(::xso::error::Error::Other("Unexpected text content".into()))
|
::core::result::Result::Err(::xso::error::Error::Other("Unexpected text content".into()))
|
||||||
} else {
|
} else {
|
||||||
::core::result::Result::Ok(::std::ops::ControlFlow::Break(
|
::core::result::Result::Ok(::core::ops::ControlFlow::Break(
|
||||||
Self::#default_state_ident { #builder_data_ident }
|
Self::#default_state_ident { #builder_data_ident }
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -286,7 +286,7 @@ impl Compound {
|
||||||
match ev {
|
match ev {
|
||||||
// EndElement in Default state -> done parsing.
|
// EndElement in Default state -> done parsing.
|
||||||
::xso::exports::rxml::Event::EndElement(_) => {
|
::xso::exports::rxml::Event::EndElement(_) => {
|
||||||
::core::result::Result::Ok(::std::ops::ControlFlow::Continue(
|
::core::result::Result::Ok(::core::ops::ControlFlow::Continue(
|
||||||
#output_cons
|
#output_cons
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -302,7 +302,7 @@ impl Compound {
|
||||||
// them at document start, and there we want to indeed
|
// them at document start, and there we want to indeed
|
||||||
// not worry about them being in front of the first
|
// not worry about them being in front of the first
|
||||||
// element.
|
// element.
|
||||||
::xso::exports::rxml::Event::XmlDeclaration(_, ::xso::exports::rxml::XmlVersion::V1_0) => ::core::result::Result::Ok(::std::ops::ControlFlow::Break(
|
::xso::exports::rxml::Event::XmlDeclaration(_, ::xso::exports::rxml::XmlVersion::V1_0) => ::core::result::Result::Ok(::core::ops::ControlFlow::Break(
|
||||||
Self::#default_state_ident { #builder_data_ident }
|
Self::#default_state_ident { #builder_data_ident }
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -513,7 +513,7 @@ impl Compound {
|
||||||
states,
|
states,
|
||||||
destructure,
|
destructure,
|
||||||
init: quote! {
|
init: quote! {
|
||||||
Self::#element_head_start_state_ident { #dummy_ident: ::std::marker::PhantomData, #name_ident: name.1, #ns_ident: name.0, #start_init }
|
Self::#element_head_start_state_ident { #dummy_ident: ::core::marker::PhantomData, #name_ident: name.1, #ns_ident: name.0, #start_init }
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
|
|
||||||
//! Infrastructure for contextual error messages
|
//! Infrastructure for contextual error messages
|
||||||
|
|
||||||
use std::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use syn::*;
|
use syn::*;
|
||||||
|
|
||||||
/// Reference to a compound field's parent
|
/// Reference to a compound field's parent
|
||||||
///
|
///
|
||||||
/// This reference can be converted to a hopefully-useful human-readable
|
/// This reference can be converted to a hopefully-useful human-readable
|
||||||
/// string via [`std::fmt::Display`].
|
/// string via [`core::fmt::Display`].
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(super) enum ParentRef {
|
pub(super) enum ParentRef {
|
||||||
/// The parent is addressable by a path, e.g. a struct type or enum
|
/// The parent is addressable by a path, e.g. a struct type or enum
|
||||||
|
|
@ -99,7 +99,7 @@ impl ParentRef {
|
||||||
/// Ephemeral struct to create a nice human-readable representation of
|
/// Ephemeral struct to create a nice human-readable representation of
|
||||||
/// [`syn::Member`].
|
/// [`syn::Member`].
|
||||||
///
|
///
|
||||||
/// It implements [`std::fmt::Display`] for that purpose and is otherwise of
|
/// It implements [`core::fmt::Display`] for that purpose and is otherwise of
|
||||||
/// little use.
|
/// little use.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
struct FieldName<'x>(&'x Member);
|
struct FieldName<'x>(&'x Member);
|
||||||
|
|
|
||||||
|
|
@ -622,7 +622,7 @@ impl FieldDef {
|
||||||
Ok(FieldBuilderPart::Nested {
|
Ok(FieldBuilderPart::Nested {
|
||||||
extra_defs,
|
extra_defs,
|
||||||
value: FieldTempInit {
|
value: FieldTempInit {
|
||||||
init: quote! { ::std::option::Option::None },
|
init: quote! { ::core::option::Option::None },
|
||||||
ty: option_ty(self.ty.clone()),
|
ty: option_ty(self.ty.clone()),
|
||||||
},
|
},
|
||||||
matcher: quote! {
|
matcher: quote! {
|
||||||
|
|
@ -637,12 +637,12 @@ impl FieldDef {
|
||||||
},
|
},
|
||||||
builder,
|
builder,
|
||||||
collect: quote! {
|
collect: quote! {
|
||||||
#field_access = ::std::option::Option::Some(#fetch);
|
#field_access = ::core::option::Option::Some(#fetch);
|
||||||
},
|
},
|
||||||
finalize: quote! {
|
finalize: quote! {
|
||||||
match #field_access {
|
match #field_access {
|
||||||
::std::option::Option::Some(value) => value,
|
::core::option::Option::Some(value) => value,
|
||||||
::std::option::Option::None => #on_absent,
|
::core::option::Option::None => #on_absent,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ fn from_xml_impl(input: Item) -> Result<TokenStream> {
|
||||||
|
|
||||||
#[cfg(feature = "minidom")]
|
#[cfg(feature = "minidom")]
|
||||||
result.extend(quote! {
|
result.extend(quote! {
|
||||||
impl ::std::convert::TryFrom<::xso::exports::minidom::Element> for #ident {
|
impl ::core::convert::TryFrom<::xso::exports::minidom::Element> for #ident {
|
||||||
type Error = ::xso::error::FromElementError;
|
type Error = ::xso::error::FromElementError;
|
||||||
|
|
||||||
fn try_from(other: ::xso::exports::minidom::Element) -> ::core::result::Result<Self, Self::Error> {
|
fn try_from(other: ::xso::exports::minidom::Element) -> ::core::result::Result<Self, Self::Error> {
|
||||||
|
|
@ -147,7 +147,7 @@ fn as_xml_impl(input: Item) -> Result<TokenStream> {
|
||||||
|
|
||||||
#[cfg(all(feature = "minidom", feature = "panicking-into-impl"))]
|
#[cfg(all(feature = "minidom", feature = "panicking-into-impl"))]
|
||||||
result.extend(quote! {
|
result.extend(quote! {
|
||||||
impl ::std::convert::From<#ident> for ::xso::exports::minidom::Element {
|
impl ::core::convert::From<#ident> for ::xso::exports::minidom::Element {
|
||||||
fn from(other: #ident) -> Self {
|
fn from(other: #ident) -> Self {
|
||||||
::xso::transform(other).expect("seamless conversion into minidom::Element")
|
::xso::transform(other).expect("seamless conversion into minidom::Element")
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +156,7 @@ fn as_xml_impl(input: Item) -> Result<TokenStream> {
|
||||||
|
|
||||||
#[cfg(all(feature = "minidom", not(feature = "panicking-into-impl")))]
|
#[cfg(all(feature = "minidom", not(feature = "panicking-into-impl")))]
|
||||||
result.extend(quote! {
|
result.extend(quote! {
|
||||||
impl ::std::convert::TryFrom<#ident> for ::xso::exports::minidom::Element {
|
impl ::core::convert::TryFrom<#ident> for ::xso::exports::minidom::Element {
|
||||||
type Error = ::xso::error::Error;
|
type Error = ::xso::error::Error;
|
||||||
|
|
||||||
fn try_from(other: #ident) -> ::core::result::Result<Self, Self::Error> {
|
fn try_from(other: #ident) -> ::core::result::Result<Self, Self::Error> {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
//! This module is concerned with parsing attributes from the Rust "meta"
|
//! This module is concerned with parsing attributes from the Rust "meta"
|
||||||
//! annotations on structs, enums, enum variants and fields.
|
//! annotations on structs, enums, enum variants and fields.
|
||||||
|
|
||||||
use std::hash::{Hash, Hasher};
|
use core::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::{quote, quote_spanned};
|
use quote::{quote, quote_spanned};
|
||||||
|
|
|
||||||
|
|
@ -280,8 +280,8 @@ impl AsItemsSubmachine {
|
||||||
Self::#name { #destructure } => {
|
Self::#name { #destructure } => {
|
||||||
let mut #uses_mut = #uses_mut;
|
let mut #uses_mut = #uses_mut;
|
||||||
match #advance_body {
|
match #advance_body {
|
||||||
::std::option::Option::Some(item) => {
|
::core::option::Option::Some(item) => {
|
||||||
::std::result::Result::Ok((::std::option::Option::Some(Self::#name { #destructure }), ::std::option::Option::Some(item)))
|
::core::result::Result::Ok((::core::option::Option::Some(Self::#name { #destructure }), ::core::option::Option::Some(item)))
|
||||||
},
|
},
|
||||||
item => { #footer },
|
item => { #footer },
|
||||||
}
|
}
|
||||||
|
|
@ -496,14 +496,14 @@ impl FromEventsStateMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl #state_ty_ident {
|
impl #state_ty_ident {
|
||||||
fn advance(mut self, ev: ::xso::exports::rxml::Event) -> ::core::result::Result<::std::ops::ControlFlow<Self, #output_ty>, ::xso::error::Error> {
|
fn advance(mut self, ev: ::xso::exports::rxml::Event) -> ::core::result::Result<::core::ops::ControlFlow<Self, #output_ty>, ::xso::error::Error> {
|
||||||
match self {
|
match self {
|
||||||
#advance_match_arms
|
#advance_match_arms
|
||||||
}.and_then(|__ok| {
|
}.and_then(|__ok| {
|
||||||
match __ok {
|
match __ok {
|
||||||
::std::ops::ControlFlow::Break(st) => ::core::result::Result::Ok(::std::ops::ControlFlow::Break(st)),
|
::core::ops::ControlFlow::Break(st) => ::core::result::Result::Ok(::core::ops::ControlFlow::Break(st)),
|
||||||
::std::ops::ControlFlow::Continue(result) => {
|
::core::ops::ControlFlow::Continue(result) => {
|
||||||
::core::result::Result::Ok(::std::ops::ControlFlow::Continue(result))
|
::core::result::Result::Ok(::core::ops::ControlFlow::Continue(result))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -528,8 +528,8 @@ impl FromEventsStateMachine {
|
||||||
fn feed(&mut self, ev: ::xso::exports::rxml::Event) -> ::core::result::Result<::core::option::Option<Self::Output>, ::xso::error::Error> {
|
fn feed(&mut self, ev: ::xso::exports::rxml::Event) -> ::core::result::Result<::core::option::Option<Self::Output>, ::xso::error::Error> {
|
||||||
let inner = self.0.take().expect("feed called after completion");
|
let inner = self.0.take().expect("feed called after completion");
|
||||||
match inner.advance(ev)? {
|
match inner.advance(ev)? {
|
||||||
::std::ops::ControlFlow::Continue(value) => ::core::result::Result::Ok(::core::option::Option::Some(value)),
|
::core::ops::ControlFlow::Continue(value) => ::core::result::Result::Ok(::core::option::Option::Some(value)),
|
||||||
::std::ops::ControlFlow::Break(st) => {
|
::core::ops::ControlFlow::Break(st) => {
|
||||||
self.0 = ::core::option::Option::Some(st);
|
self.0 = ::core::option::Option::Some(st);
|
||||||
::core::result::Result::Ok(::core::option::Option::None)
|
::core::result::Result::Ok(::core::option::Option::None)
|
||||||
}
|
}
|
||||||
|
|
@ -651,7 +651,7 @@ impl AsItemsStateMachine {
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let input_ty_ref_text = make_ty_ref(input_ty_ref);
|
let input_ty_ref_text = make_ty_ref(input_ty_ref);
|
||||||
let docstr = format!("Convert a {0} into XML events.\n\nThis type is generated using the [`macro@xso::AsXml`] derive macro and implements [`std::iter:Iterator`] for {0}.", input_ty_ref_text);
|
let docstr = format!("Convert a {0} into XML events.\n\nThis type is generated using the [`macro@xso::AsXml`] derive macro and implements [`core::iter:Iterator`] for {0}.", input_ty_ref_text);
|
||||||
|
|
||||||
let init_body = if variants.len() == 1 {
|
let init_body = if variants.len() == 1 {
|
||||||
let AsItemsEntryPoint { destructure, init } = variants.remove(0);
|
let AsItemsEntryPoint { destructure, init } = variants.remove(0);
|
||||||
|
|
@ -700,7 +700,7 @@ impl AsItemsStateMachine {
|
||||||
#[doc = #docstr]
|
#[doc = #docstr]
|
||||||
#vis struct #item_iter_ty(::core::option::Option<#state_ty_ident<#item_iter_ty_lifetime>>);
|
#vis struct #item_iter_ty(::core::option::Option<#state_ty_ident<#item_iter_ty_lifetime>>);
|
||||||
|
|
||||||
impl<#item_iter_ty_lifetime> ::std::iter::Iterator for #item_iter_ty {
|
impl<#item_iter_ty_lifetime> ::core::iter::Iterator for #item_iter_ty {
|
||||||
type Item = ::core::result::Result<::xso::Item<#item_iter_ty_lifetime>, ::xso::error::Error>;
|
type Item = ::core::result::Result<::xso::Item<#item_iter_ty_lifetime>, ::xso::error::Error>;
|
||||||
|
|
||||||
fn next(&mut self) -> ::core::option::Option<Self::Item> {
|
fn next(&mut self) -> ::core::option::Option<Self::Item> {
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ pub(crate) fn as_optional_xml_text_fn(ty: Type) -> Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [`syn::Expr`] referring to
|
/// Construct a [`syn::Expr`] referring to
|
||||||
/// `<#of_ty as ::std::default::Default>::default`.
|
/// `<#of_ty as ::core::default::Default>::default`.
|
||||||
pub(crate) fn default_fn(of_ty: Type) -> Expr {
|
pub(crate) fn default_fn(of_ty: Type) -> Expr {
|
||||||
let span = of_ty.span();
|
let span = of_ty.span();
|
||||||
Expr::Path(ExprPath {
|
Expr::Path(ExprPath {
|
||||||
|
|
@ -211,7 +211,7 @@ pub(crate) fn default_fn(of_ty: Type) -> Expr {
|
||||||
}),
|
}),
|
||||||
segments: [
|
segments: [
|
||||||
PathSegment {
|
PathSegment {
|
||||||
ident: Ident::new("std", span),
|
ident: Ident::new("core", span),
|
||||||
arguments: PathArguments::None,
|
arguments: PathArguments::None,
|
||||||
},
|
},
|
||||||
PathSegment {
|
PathSegment {
|
||||||
|
|
@ -373,7 +373,7 @@ pub(crate) fn ref_ty(ty: Type, lifetime: Lifetime) -> Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [`syn::Type`] referring to
|
/// Construct a [`syn::Type`] referring to
|
||||||
/// `::std::marker::PhantomData<&#lifetime ()>`.
|
/// `::core::marker::PhantomData<&#lifetime ()>`.
|
||||||
pub(crate) fn phantom_lifetime_ty(lifetime: Lifetime) -> Type {
|
pub(crate) fn phantom_lifetime_ty(lifetime: Lifetime) -> Type {
|
||||||
let span = lifetime.span();
|
let span = lifetime.span();
|
||||||
let dummy = Type::Tuple(TypeTuple {
|
let dummy = Type::Tuple(TypeTuple {
|
||||||
|
|
@ -388,7 +388,7 @@ pub(crate) fn phantom_lifetime_ty(lifetime: Lifetime) -> Type {
|
||||||
}),
|
}),
|
||||||
segments: [
|
segments: [
|
||||||
PathSegment {
|
PathSegment {
|
||||||
ident: Ident::new("std", span),
|
ident: Ident::new("core", span),
|
||||||
arguments: PathArguments::None,
|
arguments: PathArguments::None,
|
||||||
},
|
},
|
||||||
PathSegment {
|
PathSegment {
|
||||||
|
|
@ -475,7 +475,7 @@ pub(crate) fn from_events_fn(of_ty: Type) -> Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [`syn::Type`] which wraps the given `ty` in
|
/// Construct a [`syn::Type`] which wraps the given `ty` in
|
||||||
/// `::std::option::Option<_>`.
|
/// `::core::option::Option<_>`.
|
||||||
pub(crate) fn option_ty(ty: Type) -> Type {
|
pub(crate) fn option_ty(ty: Type) -> Type {
|
||||||
let span = ty.span();
|
let span = ty.span();
|
||||||
Type::Path(TypePath {
|
Type::Path(TypePath {
|
||||||
|
|
@ -486,7 +486,7 @@ pub(crate) fn option_ty(ty: Type) -> Type {
|
||||||
}),
|
}),
|
||||||
segments: [
|
segments: [
|
||||||
PathSegment {
|
PathSegment {
|
||||||
ident: Ident::new("std", span),
|
ident: Ident::new("core", span),
|
||||||
arguments: PathArguments::None,
|
arguments: PathArguments::None,
|
||||||
},
|
},
|
||||||
PathSegment {
|
PathSegment {
|
||||||
|
|
@ -642,7 +642,7 @@ fn into_iterator_of(of_ty: Type) -> (Span, TypePath) {
|
||||||
}),
|
}),
|
||||||
segments: [
|
segments: [
|
||||||
PathSegment {
|
PathSegment {
|
||||||
ident: Ident::new("std", span),
|
ident: Ident::new("core", span),
|
||||||
arguments: PathArguments::None,
|
arguments: PathArguments::None,
|
||||||
},
|
},
|
||||||
PathSegment {
|
PathSegment {
|
||||||
|
|
@ -699,7 +699,7 @@ pub(crate) fn into_iterator_into_iter_fn(of_ty: Type) -> Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [`syn::Expr`] referring to
|
/// Construct a [`syn::Expr`] referring to
|
||||||
/// `<#of_ty as ::std::iter::Extend>::extend`.
|
/// `<#of_ty as ::core::iter::Extend>::extend`.
|
||||||
pub(crate) fn extend_fn(of_ty: Type, item_ty: Type) -> Expr {
|
pub(crate) fn extend_fn(of_ty: Type, item_ty: Type) -> Expr {
|
||||||
let span = of_ty.span();
|
let span = of_ty.span();
|
||||||
Expr::Path(ExprPath {
|
Expr::Path(ExprPath {
|
||||||
|
|
@ -717,7 +717,7 @@ pub(crate) fn extend_fn(of_ty: Type, item_ty: Type) -> Expr {
|
||||||
}),
|
}),
|
||||||
segments: [
|
segments: [
|
||||||
PathSegment {
|
PathSegment {
|
||||||
ident: Ident::new("std", span),
|
ident: Ident::new("core", span),
|
||||||
arguments: PathArguments::None,
|
arguments: PathArguments::None,
|
||||||
},
|
},
|
||||||
PathSegment {
|
PathSegment {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue