serde/test_suite/tests/expand/generic_struct.expanded.rs

595 lines
24 KiB
Rust
Raw Normal View History

2019-10-31 13:32:34 -05:00
use serde::{Deserialize, Serialize};
pub struct GenericStruct<T> {
x: T,
}
#[doc(hidden)]
2019-10-31 13:32:34 -05:00
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
2020-06-07 00:41:07 -05:00
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
2019-10-31 13:32:34 -05:00
extern crate serde as _serde;
#[automatically_derived]
impl<T> _serde::Serialize for GenericStruct<T>
where
T: _serde::Serialize,
{
fn serialize<__S>(
&self,
__serializer: __S,
) -> _serde::__private::Result<__S::Ok, __S::Error>
2019-10-31 13:32:34 -05:00
where
__S: _serde::Serializer,
{
let mut __serde_state = match _serde::Serializer::serialize_struct(
__serializer,
"GenericStruct",
false as usize + 1,
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
};
match _serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "x", &self.x) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
};
_serde::ser::SerializeStruct::end(__serde_state)
}
}
};
#[doc(hidden)]
2019-10-31 13:32:34 -05:00
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
2020-06-07 00:41:07 -05:00
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
2019-10-31 13:32:34 -05:00
extern crate serde as _serde;
#[automatically_derived]
impl<'de, T> _serde::Deserialize<'de> for GenericStruct<T>
where
T: _serde::Deserialize<'de>,
{
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
2019-10-31 13:32:34 -05:00
where
__D: _serde::Deserializer<'de>,
{
#[allow(non_camel_case_types)]
enum __Field {
__field0,
__ignore,
}
struct __FieldVisitor;
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
type Value = __Field;
fn expecting(
&self,
__formatter: &mut _serde::__private::Formatter,
) -> _serde::__private::fmt::Result {
_serde::__private::Formatter::write_str(__formatter, "field identifier")
2019-10-31 13:32:34 -05:00
}
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
2019-10-31 13:32:34 -05:00
where
__E: _serde::de::Error,
{
match __value {
0u64 => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
2019-10-31 13:32:34 -05:00
}
}
fn visit_str<__E>(
self,
__value: &str,
) -> _serde::__private::Result<Self::Value, __E>
2019-10-31 13:32:34 -05:00
where
__E: _serde::de::Error,
{
match __value {
"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
2019-10-31 13:32:34 -05:00
}
}
fn visit_bytes<__E>(
self,
__value: &[u8],
) -> _serde::__private::Result<Self::Value, __E>
2019-10-31 13:32:34 -05:00
where
__E: _serde::de::Error,
{
match __value {
b"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
2019-10-31 13:32:34 -05:00
}
}
}
impl<'de> _serde::Deserialize<'de> for __Field {
#[inline]
fn deserialize<__D>(
__deserializer: __D,
) -> _serde::__private::Result<Self, __D::Error>
2019-10-31 13:32:34 -05:00
where
__D: _serde::Deserializer<'de>,
{
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
}
}
struct __Visitor<'de, T>
where
T: _serde::Deserialize<'de>,
{
marker: _serde::__private::PhantomData<GenericStruct<T>>,
lifetime: _serde::__private::PhantomData<&'de ()>,
2019-10-31 13:32:34 -05:00
}
impl<'de, T> _serde::de::Visitor<'de> for __Visitor<'de, T>
where
T: _serde::Deserialize<'de>,
{
type Value = GenericStruct<T>;
fn expecting(
&self,
__formatter: &mut _serde::__private::Formatter,
) -> _serde::__private::fmt::Result {
_serde::__private::Formatter::write_str(__formatter, "struct GenericStruct")
2019-10-31 13:32:34 -05:00
}
#[inline]
fn visit_seq<__A>(
self,
mut __seq: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
2019-10-31 13:32:34 -05:00
where
__A: _serde::de::SeqAccess<'de>,
{
let __field0 = match match _serde::de::SeqAccess::next_element::<T>(&mut __seq)
{
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
} {
_serde::__private::Some(__value) => __value,
_serde::__private::None => {
return _serde::__private::Err(_serde::de::Error::invalid_length(
2019-10-31 13:32:34 -05:00
0usize,
&"struct GenericStruct with 1 element",
));
}
};
_serde::__private::Ok(GenericStruct { x: __field0 })
2019-10-31 13:32:34 -05:00
}
#[inline]
fn visit_map<__A>(
self,
mut __map: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
2019-10-31 13:32:34 -05:00
where
__A: _serde::de::MapAccess<'de>,
{
let mut __field0: _serde::__private::Option<T> = _serde::__private::None;
while let _serde::__private::Some(__key) =
2019-10-31 13:32:34 -05:00
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
}
{
match __key {
__Field::__field0 => {
if _serde::__private::Option::is_some(&__field0) {
return _serde::__private::Err(
2019-10-31 13:32:34 -05:00
<__A::Error as _serde::de::Error>::duplicate_field("x"),
);
}
__field0 = _serde::__private::Some(
2019-10-31 13:32:34 -05:00
match _serde::de::MapAccess::next_value::<T>(&mut __map) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
},
);
}
_ => {
let _ = match _serde::de::MapAccess::next_value::<
_serde::de::IgnoredAny,
>(&mut __map)
{
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
};
}
}
}
let __field0 = match __field0 {
_serde::__private::Some(__field0) => __field0,
_serde::__private::None => {
match _serde::__private::de::missing_field("x") {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
2019-10-31 13:32:34 -05:00
}
}
2019-10-31 13:32:34 -05:00
};
_serde::__private::Ok(GenericStruct { x: __field0 })
2019-10-31 13:32:34 -05:00
}
}
const FIELDS: &'static [&'static str] = &["x"];
_serde::Deserializer::deserialize_struct(
__deserializer,
"GenericStruct",
FIELDS,
__Visitor {
marker: _serde::__private::PhantomData::<GenericStruct<T>>,
lifetime: _serde::__private::PhantomData,
2019-10-31 13:32:34 -05:00
},
)
}
fn deserialize_in_place<__D>(
__deserializer: __D,
__place: &mut Self,
) -> _serde::__private::Result<(), __D::Error>
2019-10-31 13:32:34 -05:00
where
__D: _serde::Deserializer<'de>,
{
#[allow(non_camel_case_types)]
enum __Field {
__field0,
__ignore,
}
struct __FieldVisitor;
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
type Value = __Field;
fn expecting(
&self,
__formatter: &mut _serde::__private::Formatter,
) -> _serde::__private::fmt::Result {
_serde::__private::Formatter::write_str(__formatter, "field identifier")
2019-10-31 13:32:34 -05:00
}
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
2019-10-31 13:32:34 -05:00
where
__E: _serde::de::Error,
{
match __value {
0u64 => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
2019-10-31 13:32:34 -05:00
}
}
fn visit_str<__E>(
self,
__value: &str,
) -> _serde::__private::Result<Self::Value, __E>
2019-10-31 13:32:34 -05:00
where
__E: _serde::de::Error,
{
match __value {
"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
2019-10-31 13:32:34 -05:00
}
}
fn visit_bytes<__E>(
self,
__value: &[u8],
) -> _serde::__private::Result<Self::Value, __E>
2019-10-31 13:32:34 -05:00
where
__E: _serde::de::Error,
{
match __value {
b"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
2019-10-31 13:32:34 -05:00
}
}
}
impl<'de> _serde::Deserialize<'de> for __Field {
#[inline]
fn deserialize<__D>(
__deserializer: __D,
) -> _serde::__private::Result<Self, __D::Error>
2019-10-31 13:32:34 -05:00
where
__D: _serde::Deserializer<'de>,
{
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
}
}
struct __Visitor<'de, 'place, T: 'place>
where
T: _serde::Deserialize<'de>,
{
place: &'place mut GenericStruct<T>,
lifetime: _serde::__private::PhantomData<&'de ()>,
2019-10-31 13:32:34 -05:00
}
impl<'de, 'place, T: 'place> _serde::de::Visitor<'de> for __Visitor<'de, 'place, T>
where
T: _serde::Deserialize<'de>,
{
type Value = ();
fn expecting(
&self,
__formatter: &mut _serde::__private::Formatter,
) -> _serde::__private::fmt::Result {
_serde::__private::Formatter::write_str(__formatter, "struct GenericStruct")
2019-10-31 13:32:34 -05:00
}
#[inline]
fn visit_seq<__A>(
self,
mut __seq: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
2019-10-31 13:32:34 -05:00
where
__A: _serde::de::SeqAccess<'de>,
{
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
2019-10-31 13:32:34 -05:00
&mut __seq,
_serde::__private::de::InPlaceSeed(&mut self.place.x),
2019-10-31 13:32:34 -05:00
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
} {
return _serde::__private::Err(_serde::de::Error::invalid_length(
2019-10-31 13:32:34 -05:00
0usize,
&"struct GenericStruct with 1 element",
));
}
_serde::__private::Ok(())
2019-10-31 13:32:34 -05:00
}
#[inline]
fn visit_map<__A>(
self,
mut __map: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
2019-10-31 13:32:34 -05:00
where
__A: _serde::de::MapAccess<'de>,
{
let mut __field0: bool = false;
while let _serde::__private::Some(__key) =
2019-10-31 13:32:34 -05:00
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
}
{
match __key {
__Field::__field0 => {
if __field0 {
return _serde::__private::Err(
2019-10-31 13:32:34 -05:00
<__A::Error as _serde::de::Error>::duplicate_field("x"),
);
}
match _serde::de::MapAccess::next_value_seed(
&mut __map,
_serde::__private::de::InPlaceSeed(&mut self.place.x),
2019-10-31 13:32:34 -05:00
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
};
__field0 = true;
}
_ => {
let _ = match _serde::de::MapAccess::next_value::<
_serde::de::IgnoredAny,
>(&mut __map)
{
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
};
}
}
}
if !__field0 {
self.place.x = match _serde::__private::de::missing_field("x") {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
};
};
_serde::__private::Ok(())
2019-10-31 13:32:34 -05:00
}
}
const FIELDS: &'static [&'static str] = &["x"];
_serde::Deserializer::deserialize_struct(
__deserializer,
"GenericStruct",
FIELDS,
__Visitor {
place: __place,
lifetime: _serde::__private::PhantomData,
2019-10-31 13:32:34 -05:00
},
)
}
}
};
pub struct GenericNewTypeStruct<T>(T);
#[doc(hidden)]
2019-10-31 13:32:34 -05:00
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
2020-06-07 00:41:07 -05:00
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
2019-10-31 13:32:34 -05:00
extern crate serde as _serde;
#[automatically_derived]
impl<T> _serde::Serialize for GenericNewTypeStruct<T>
where
T: _serde::Serialize,
{
fn serialize<__S>(
&self,
__serializer: __S,
) -> _serde::__private::Result<__S::Ok, __S::Error>
2019-10-31 13:32:34 -05:00
where
__S: _serde::Serializer,
{
_serde::Serializer::serialize_newtype_struct(
__serializer,
"GenericNewTypeStruct",
&self.0,
)
}
}
};
#[doc(hidden)]
2019-10-31 13:32:34 -05:00
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
2020-06-07 00:41:07 -05:00
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
2019-10-31 13:32:34 -05:00
extern crate serde as _serde;
#[automatically_derived]
impl<'de, T> _serde::Deserialize<'de> for GenericNewTypeStruct<T>
where
T: _serde::Deserialize<'de>,
{
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
2019-10-31 13:32:34 -05:00
where
__D: _serde::Deserializer<'de>,
{
struct __Visitor<'de, T>
where
T: _serde::Deserialize<'de>,
{
marker: _serde::__private::PhantomData<GenericNewTypeStruct<T>>,
lifetime: _serde::__private::PhantomData<&'de ()>,
2019-10-31 13:32:34 -05:00
}
impl<'de, T> _serde::de::Visitor<'de> for __Visitor<'de, T>
where
T: _serde::Deserialize<'de>,
{
type Value = GenericNewTypeStruct<T>;
fn expecting(
&self,
__formatter: &mut _serde::__private::Formatter,
) -> _serde::__private::fmt::Result {
_serde::__private::Formatter::write_str(
2019-10-31 13:32:34 -05:00
__formatter,
"tuple struct GenericNewTypeStruct",
)
}
#[inline]
fn visit_newtype_struct<__E>(
self,
__e: __E,
) -> _serde::__private::Result<Self::Value, __E::Error>
2019-10-31 13:32:34 -05:00
where
__E: _serde::Deserializer<'de>,
{
let __field0: T = match <T as _serde::Deserialize>::deserialize(__e) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
};
_serde::__private::Ok(GenericNewTypeStruct(__field0))
2019-10-31 13:32:34 -05:00
}
#[inline]
fn visit_seq<__A>(
self,
mut __seq: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
2019-10-31 13:32:34 -05:00
where
__A: _serde::de::SeqAccess<'de>,
{
let __field0 = match match _serde::de::SeqAccess::next_element::<T>(&mut __seq)
{
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
} {
_serde::__private::Some(__value) => __value,
_serde::__private::None => {
return _serde::__private::Err(_serde::de::Error::invalid_length(
2019-10-31 13:32:34 -05:00
0usize,
&"tuple struct GenericNewTypeStruct with 1 element",
));
}
};
_serde::__private::Ok(GenericNewTypeStruct(__field0))
2019-10-31 13:32:34 -05:00
}
}
_serde::Deserializer::deserialize_newtype_struct(
__deserializer,
"GenericNewTypeStruct",
__Visitor {
marker: _serde::__private::PhantomData::<GenericNewTypeStruct<T>>,
lifetime: _serde::__private::PhantomData,
2019-10-31 13:32:34 -05:00
},
)
}
fn deserialize_in_place<__D>(
__deserializer: __D,
__place: &mut Self,
) -> _serde::__private::Result<(), __D::Error>
2019-10-31 13:32:34 -05:00
where
__D: _serde::Deserializer<'de>,
{
struct __Visitor<'de, 'place, T: 'place>
where
T: _serde::Deserialize<'de>,
{
place: &'place mut GenericNewTypeStruct<T>,
lifetime: _serde::__private::PhantomData<&'de ()>,
2019-10-31 13:32:34 -05:00
}
impl<'de, 'place, T: 'place> _serde::de::Visitor<'de> for __Visitor<'de, 'place, T>
where
T: _serde::Deserialize<'de>,
{
type Value = ();
fn expecting(
&self,
__formatter: &mut _serde::__private::Formatter,
) -> _serde::__private::fmt::Result {
_serde::__private::Formatter::write_str(
2019-10-31 13:32:34 -05:00
__formatter,
"tuple struct GenericNewTypeStruct",
)
}
#[inline]
fn visit_newtype_struct<__E>(
self,
__e: __E,
) -> _serde::__private::Result<Self::Value, __E::Error>
2019-10-31 13:32:34 -05:00
where
__E: _serde::Deserializer<'de>,
{
_serde::Deserialize::deserialize_in_place(__e, &mut self.place.0)
}
#[inline]
fn visit_seq<__A>(
self,
mut __seq: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
2019-10-31 13:32:34 -05:00
where
__A: _serde::de::SeqAccess<'de>,
{
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
2019-10-31 13:32:34 -05:00
&mut __seq,
_serde::__private::de::InPlaceSeed(&mut self.place.0),
2019-10-31 13:32:34 -05:00
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
2019-10-31 13:32:34 -05:00
}
} {
return _serde::__private::Err(_serde::de::Error::invalid_length(
2019-10-31 13:32:34 -05:00
0usize,
&"tuple struct GenericNewTypeStruct with 1 element",
));
}
_serde::__private::Ok(())
2019-10-31 13:32:34 -05:00
}
}
_serde::Deserializer::deserialize_newtype_struct(
__deserializer,
"GenericNewTypeStruct",
__Visitor {
place: __place,
lifetime: _serde::__private::PhantomData,
2019-10-31 13:32:34 -05:00
},
)
}
}
};