serde/test_suite/tests/expand/generic_struct.expanded.rs
David Tolnay dd1f4b483e
Make it clearer that the private implementation details are private
Both of these modules are doc(hidden) and commented "Not public API",
but incorrect downstream code sometimes still references them. Naming
the module __private will make it more likely to be noticed in code
review.
2021-01-08 19:55:31 -08:00

601 lines
24 KiB
Rust

use serde::{Deserialize, Serialize};
pub struct GenericStruct<T> {
x: T,
}
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
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>
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);
}
};
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);
}
};
_serde::ser::SerializeStruct::end(__serde_state)
}
}
};
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
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>
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")
}
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
where
__E: _serde::de::Error,
{
match __value {
0u64 => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Err(_serde::de::Error::invalid_value(
_serde::de::Unexpected::Unsigned(__value),
&"field index 0 <= i < 1",
)),
}
}
fn visit_str<__E>(
self,
__value: &str,
) -> _serde::__private::Result<Self::Value, __E>
where
__E: _serde::de::Error,
{
match __value {
"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
}
}
fn visit_bytes<__E>(
self,
__value: &[u8],
) -> _serde::__private::Result<Self::Value, __E>
where
__E: _serde::de::Error,
{
match __value {
b"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
}
}
}
impl<'de> _serde::Deserialize<'de> for __Field {
#[inline]
fn deserialize<__D>(
__deserializer: __D,
) -> _serde::__private::Result<Self, __D::Error>
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 ()>,
}
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")
}
#[inline]
fn visit_seq<__A>(
self,
mut __seq: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
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);
}
} {
_serde::__private::Some(__value) => __value,
_serde::__private::None => {
return _serde::__private::Err(_serde::de::Error::invalid_length(
0usize,
&"struct GenericStruct with 1 element",
));
}
};
_serde::__private::Ok(GenericStruct { x: __field0 })
}
#[inline]
fn visit_map<__A>(
self,
mut __map: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
where
__A: _serde::de::MapAccess<'de>,
{
let mut __field0: _serde::__private::Option<T> = _serde::__private::None;
while let _serde::__private::Some(__key) =
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
}
{
match __key {
__Field::__field0 => {
if _serde::__private::Option::is_some(&__field0) {
return _serde::__private::Err(
<__A::Error as _serde::de::Error>::duplicate_field("x"),
);
}
__field0 = _serde::__private::Some(
match _serde::de::MapAccess::next_value::<T>(&mut __map) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
},
);
}
_ => {
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);
}
};
}
}
}
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);
}
}
}
};
_serde::__private::Ok(GenericStruct { x: __field0 })
}
}
const FIELDS: &'static [&'static str] = &["x"];
_serde::Deserializer::deserialize_struct(
__deserializer,
"GenericStruct",
FIELDS,
__Visitor {
marker: _serde::__private::PhantomData::<GenericStruct<T>>,
lifetime: _serde::__private::PhantomData,
},
)
}
fn deserialize_in_place<__D>(
__deserializer: __D,
__place: &mut Self,
) -> _serde::__private::Result<(), __D::Error>
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")
}
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
where
__E: _serde::de::Error,
{
match __value {
0u64 => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Err(_serde::de::Error::invalid_value(
_serde::de::Unexpected::Unsigned(__value),
&"field index 0 <= i < 1",
)),
}
}
fn visit_str<__E>(
self,
__value: &str,
) -> _serde::__private::Result<Self::Value, __E>
where
__E: _serde::de::Error,
{
match __value {
"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
}
}
fn visit_bytes<__E>(
self,
__value: &[u8],
) -> _serde::__private::Result<Self::Value, __E>
where
__E: _serde::de::Error,
{
match __value {
b"x" => _serde::__private::Ok(__Field::__field0),
_ => _serde::__private::Ok(__Field::__ignore),
}
}
}
impl<'de> _serde::Deserialize<'de> for __Field {
#[inline]
fn deserialize<__D>(
__deserializer: __D,
) -> _serde::__private::Result<Self, __D::Error>
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 ()>,
}
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")
}
#[inline]
fn visit_seq<__A>(
self,
mut __seq: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
where
__A: _serde::de::SeqAccess<'de>,
{
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
&mut __seq,
_serde::__private::de::InPlaceSeed(&mut self.place.x),
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
} {
return _serde::__private::Err(_serde::de::Error::invalid_length(
0usize,
&"struct GenericStruct with 1 element",
));
}
_serde::__private::Ok(())
}
#[inline]
fn visit_map<__A>(
self,
mut __map: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
where
__A: _serde::de::MapAccess<'de>,
{
let mut __field0: bool = false;
while let _serde::__private::Some(__key) =
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
}
{
match __key {
__Field::__field0 => {
if __field0 {
return _serde::__private::Err(
<__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),
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
};
__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);
}
};
}
}
}
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);
}
};
};
_serde::__private::Ok(())
}
}
const FIELDS: &'static [&'static str] = &["x"];
_serde::Deserializer::deserialize_struct(
__deserializer,
"GenericStruct",
FIELDS,
__Visitor {
place: __place,
lifetime: _serde::__private::PhantomData,
},
)
}
}
};
pub struct GenericNewTypeStruct<T>(T);
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
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>
where
__S: _serde::Serializer,
{
_serde::Serializer::serialize_newtype_struct(
__serializer,
"GenericNewTypeStruct",
&self.0,
)
}
}
};
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () = {
#[allow(rust_2018_idioms, clippy::useless_attribute)]
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>
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 ()>,
}
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(
__formatter,
"tuple struct GenericNewTypeStruct",
)
}
#[inline]
fn visit_newtype_struct<__E>(
self,
__e: __E,
) -> _serde::__private::Result<Self::Value, __E::Error>
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);
}
};
_serde::__private::Ok(GenericNewTypeStruct(__field0))
}
#[inline]
fn visit_seq<__A>(
self,
mut __seq: __A,
) -> _serde::__private::Result<Self::Value, __A::Error>
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);
}
} {
_serde::__private::Some(__value) => __value,
_serde::__private::None => {
return _serde::__private::Err(_serde::de::Error::invalid_length(
0usize,
&"tuple struct GenericNewTypeStruct with 1 element",
));
}
};
_serde::__private::Ok(GenericNewTypeStruct(__field0))
}
}
_serde::Deserializer::deserialize_newtype_struct(
__deserializer,
"GenericNewTypeStruct",
__Visitor {
marker: _serde::__private::PhantomData::<GenericNewTypeStruct<T>>,
lifetime: _serde::__private::PhantomData,
},
)
}
fn deserialize_in_place<__D>(
__deserializer: __D,
__place: &mut Self,
) -> _serde::__private::Result<(), __D::Error>
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 ()>,
}
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,
"tuple struct GenericNewTypeStruct",
)
}
#[inline]
fn visit_newtype_struct<__E>(
self,
__e: __E,
) -> _serde::__private::Result<Self::Value, __E::Error>
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>
where
__A: _serde::de::SeqAccess<'de>,
{
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
&mut __seq,
_serde::__private::de::InPlaceSeed(&mut self.place.0),
) {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
} {
return _serde::__private::Err(_serde::de::Error::invalid_length(
0usize,
&"tuple struct GenericNewTypeStruct with 1 element",
));
}
_serde::__private::Ok(())
}
}
_serde::Deserializer::deserialize_newtype_struct(
__deserializer,
"GenericNewTypeStruct",
__Visitor {
place: __place,
lifetime: _serde::__private::PhantomData,
},
)
}
}
};