Coverage Report

Created: 2025-10-10 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/serde-1.0.136/src/ser/fmt.rs
Line
Count
Source
1
use lib::*;
2
use ser::{Error, Impossible, Serialize, Serializer};
3
4
impl Error for fmt::Error {
5
0
    fn custom<T: Display>(_msg: T) -> Self {
6
0
        fmt::Error
7
0
    }
8
}
9
10
macro_rules! fmt_primitives {
11
    ($($f:ident: $t:ty,)*) => {
12
        $(
13
0
            fn $f(self, v: $t) -> fmt::Result {
14
0
                Display::fmt(&v, self)
15
0
            }
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_i8
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_u8
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_f32
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_f64
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_i16
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_i32
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_i64
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_str
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_u16
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_u32
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_u64
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_bool
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_char
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_i128
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_u128
Unexecuted instantiation: <&mut core::fmt::Formatter as serde::ser::Serializer>::serialize_unit_struct
16
        )*
17
    };
18
}
19
20
/// ```edition2018
21
/// use serde::Serialize;
22
/// use std::fmt::{self, Display};
23
///
24
/// #[derive(Serialize)]
25
/// #[serde(rename_all = "kebab-case")]
26
/// pub enum MessageType {
27
///     StartRequest,
28
///     EndRequest,
29
/// }
30
///
31
/// impl Display for MessageType {
32
///     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33
///         self.serialize(f)
34
///     }
35
/// }
36
/// ```
37
impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
38
    type Ok = ();
39
    type Error = fmt::Error;
40
    type SerializeSeq = Impossible<(), fmt::Error>;
41
    type SerializeTuple = Impossible<(), fmt::Error>;
42
    type SerializeTupleStruct = Impossible<(), fmt::Error>;
43
    type SerializeTupleVariant = Impossible<(), fmt::Error>;
44
    type SerializeMap = Impossible<(), fmt::Error>;
45
    type SerializeStruct = Impossible<(), fmt::Error>;
46
    type SerializeStructVariant = Impossible<(), fmt::Error>;
47
48
    fmt_primitives! {
49
        serialize_bool: bool,
50
        serialize_i8: i8,
51
        serialize_i16: i16,
52
        serialize_i32: i32,
53
        serialize_i64: i64,
54
        serialize_u8: u8,
55
        serialize_u16: u16,
56
        serialize_u32: u32,
57
        serialize_u64: u64,
58
        serialize_f32: f32,
59
        serialize_f64: f64,
60
        serialize_char: char,
61
        serialize_str: &str,
62
        serialize_unit_struct: &'static str,
63
    }
64
65
    serde_if_integer128! {
66
        fmt_primitives! {
67
            serialize_i128: i128,
68
            serialize_u128: u128,
69
        }
70
    }
71
72
0
    fn serialize_unit_variant(
73
0
        self,
74
0
        _name: &'static str,
75
0
        _variant_index: u32,
76
0
        variant: &'static str,
77
0
    ) -> fmt::Result {
78
0
        Display::fmt(variant, self)
79
0
    }
80
81
0
    fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> fmt::Result
82
0
    where
83
0
        T: Serialize,
84
0
    {
85
0
        Serialize::serialize(value, self)
86
0
    }
87
88
0
    fn serialize_bytes(self, _v: &[u8]) -> fmt::Result {
89
0
        Err(fmt::Error)
90
0
    }
91
92
0
    fn serialize_none(self) -> fmt::Result {
93
0
        Err(fmt::Error)
94
0
    }
95
96
0
    fn serialize_some<T: ?Sized>(self, _value: &T) -> fmt::Result
97
0
    where
98
0
        T: Serialize,
99
0
    {
100
0
        Err(fmt::Error)
101
0
    }
102
103
0
    fn serialize_unit(self) -> fmt::Result {
104
0
        Err(fmt::Error)
105
0
    }
106
107
0
    fn serialize_newtype_variant<T: ?Sized>(
108
0
        self,
109
0
        _name: &'static str,
110
0
        _variant_index: u32,
111
0
        _variant: &'static str,
112
0
        _value: &T,
113
0
    ) -> fmt::Result
114
0
    where
115
0
        T: Serialize,
116
0
    {
117
0
        Err(fmt::Error)
118
0
    }
119
120
0
    fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, fmt::Error> {
121
0
        Err(fmt::Error)
122
0
    }
123
124
0
    fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, fmt::Error> {
125
0
        Err(fmt::Error)
126
0
    }
127
128
0
    fn serialize_tuple_struct(
129
0
        self,
130
0
        _name: &'static str,
131
0
        _len: usize,
132
0
    ) -> Result<Self::SerializeTupleStruct, fmt::Error> {
133
0
        Err(fmt::Error)
134
0
    }
135
136
0
    fn serialize_tuple_variant(
137
0
        self,
138
0
        _name: &'static str,
139
0
        _variant_index: u32,
140
0
        _variant: &'static str,
141
0
        _len: usize,
142
0
    ) -> Result<Self::SerializeTupleVariant, fmt::Error> {
143
0
        Err(fmt::Error)
144
0
    }
145
146
0
    fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, fmt::Error> {
147
0
        Err(fmt::Error)
148
0
    }
149
150
0
    fn serialize_struct(
151
0
        self,
152
0
        _name: &'static str,
153
0
        _len: usize,
154
0
    ) -> Result<Self::SerializeStruct, fmt::Error> {
155
0
        Err(fmt::Error)
156
0
    }
157
158
0
    fn serialize_struct_variant(
159
0
        self,
160
0
        _name: &'static str,
161
0
        _variant_index: u32,
162
0
        _variant: &'static str,
163
0
        _len: usize,
164
0
    ) -> Result<Self::SerializeStructVariant, fmt::Error> {
165
0
        Err(fmt::Error)
166
0
    }
167
168
0
    fn collect_str<T: ?Sized>(self, value: &T) -> fmt::Result
169
0
    where
170
0
        T: Display,
171
0
    {
172
0
        Display::fmt(value, self)
173
0
    }
174
}