Pull up types from function into module, unify style

This commit is contained in:
Mingun 2023-05-09 14:27:03 +05:00
parent 52a7d40e6e
commit f7c5d93e6a

View File

@ -3015,7 +3015,7 @@ mod flatten {
#[test] #[test]
fn structs() { fn structs() {
#[derive(Serialize, Deserialize, PartialEq, Debug)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Flatten { struct Flatten {
#[serde(flatten)] #[serde(flatten)]
x: X, x: X,
@ -3023,27 +3023,25 @@ mod flatten {
y: Y, y: Y,
} }
#[derive(Serialize, Deserialize, PartialEq, Debug)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "typeX")] #[serde(tag = "typeX")]
enum X { enum X {
A { a: i32 }, A { a: i32 },
B { b: i32 }, B { b: i32 },
} }
#[derive(Serialize, Deserialize, PartialEq, Debug)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "typeY")] #[serde(tag = "typeY")]
enum Y { enum Y {
C { c: i32 }, C { c: i32 },
D { d: i32 }, D { d: i32 },
} }
let s = Flatten { assert_tokens(
&Flatten {
x: X::B { b: 1 }, x: X::B { b: 1 },
y: Y::D { d: 2 }, y: Y::D { d: 2 },
}; },
assert_tokens(
&s,
&[ &[
Token::Map { len: None }, Token::Map { len: None },
Token::Str("typeX"), Token::Str("typeX"),
@ -3061,7 +3059,7 @@ mod flatten {
#[test] #[test]
fn unit_enum_with_unknown_fields() { fn unit_enum_with_unknown_fields() {
#[derive(Deserialize, PartialEq, Debug)] #[derive(Debug, PartialEq, Deserialize)]
struct Flatten { struct Flatten {
#[serde(flatten)] #[serde(flatten)]
x: X, x: X,
@ -3069,25 +3067,23 @@ mod flatten {
y: Y, y: Y,
} }
#[derive(Deserialize, PartialEq, Debug)] #[derive(Debug, PartialEq, Deserialize)]
#[serde(tag = "typeX")] #[serde(tag = "typeX")]
enum X { enum X {
A, A,
} }
#[derive(Deserialize, PartialEq, Debug)] #[derive(Debug, PartialEq, Deserialize)]
#[serde(tag = "typeY")] #[serde(tag = "typeY")]
enum Y { enum Y {
B { c: u32 }, B { c: u32 },
} }
let s = Flatten { assert_de_tokens(
&Flatten {
x: X::A, x: X::A,
y: Y::B { c: 0 }, y: Y::B { c: 0 },
}; },
assert_de_tokens(
&s,
&[ &[
Token::Map { len: None }, Token::Map { len: None },
Token::Str("typeX"), Token::Str("typeX"),
@ -3105,26 +3101,24 @@ mod flatten {
mod untagged { mod untagged {
use super::*; use super::*;
#[test] #[derive(Debug, PartialEq, Serialize, Deserialize)]
fn struct_() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Flatten { struct Flatten {
#[serde(flatten)] #[serde(flatten)]
data: Enum, data: Enum,
} }
#[derive(Serialize, Deserialize, PartialEq, Debug)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
enum Enum { enum Enum {
Struct { a: i32 }, Struct { a: i32 },
} }
let data = Flatten { #[test]
data: Enum::Struct { a: 0 }, fn struct_() {
};
assert_tokens( assert_tokens(
&data, &Flatten {
data: Enum::Struct { a: 0 },
},
&[ &[
Token::Map { len: None }, Token::Map { len: None },
Token::Str("a"), Token::Str("a"),