Revert parts of "Use absolute paths in generated code"

to restore compatibility with older versions of Rust.
This commit is contained in:
Jonas Platte
2020-12-17 18:25:11 +01:00
parent d19c57d23d
commit a1fc2f9fad
5 changed files with 23 additions and 19 deletions

View File

@@ -161,7 +161,7 @@ fn build_unnamed_field_visitors(fields: &syn::FieldsUnnamed) -> TokenStream {
fn #visitor(
self,
v: &::std::primitive::str,
v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> {
#fn_body
}

View File

@@ -82,7 +82,7 @@ pub fn parse(
fn visit_str(
self,
v: &::std::primitive::str,
v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> {
let content = "<".to_string() + #struct_id + ">" + v + "</" + #struct_id + ">";
::yaserde::de::from_str(&content)
@@ -114,7 +114,7 @@ pub fn parse(
fn #visitor(
self,
v: &::std::primitive::str,
v: &str,
) -> ::std::result::Result<Self::Value, ::std::string::String> {
::std::result::Result::Ok(#field_type::from_str(#map_if_bool).unwrap())
}
@@ -363,7 +363,7 @@ pub fn parse(
let event = reader.peek()?.to_owned();
::log::trace!(
"Struct {} @ {}: matching {:?}",
::std::stringify!(#name), start_depth, event,
stringify!(#name), start_depth, event,
);
match event {
::xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => {

View File

@@ -3,7 +3,7 @@ pub mod expand_enum;
pub mod expand_struct;
use crate::common::YaSerdeAttribute;
use proc_macro2::TokenStream;
use proc_macro2::{Ident, TokenStream};
use quote::quote;
pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream, String> {
@@ -29,9 +29,11 @@ pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream,
syn::Data::Union(ref _data_union) => unimplemented!(),
};
let dummy_const = Ident::new(&format!("_IMPL_YA_DESERIALIZE_FOR_{}", name), name.span());
Ok(quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = {
const #dummy_const: () = {
use ::std::str::FromStr as _;
use ::yaserde::Visitor as _;