@@ -78,17 +78,38 @@ pub enum QuoteStyle {
78
78
Never ,
79
79
}
80
80
81
+ const fn default_delimiter ( ) -> u8 {
82
+ b','
83
+ }
84
+
85
+ const fn default_escape ( ) -> u8 {
86
+ b','
87
+ }
88
+
89
+ const fn default_double_quote ( ) -> bool {
90
+ true
91
+ }
92
+
81
93
/// Config used to build a `CsvSerializer`.
82
94
#[ crate :: configurable_component]
83
95
#[ derive( Debug , Clone ) ]
84
96
pub struct CsvSerializerOptions {
85
97
/// The field delimiter to use when writing CSV.
98
+ #[ serde(
99
+ default = "default_delimiter" ,
100
+ with = "vector_core::serde::ascii_char" ,
101
+ skip_serializing_if = "vector_core::serde::skip_serializing_if_default"
102
+ ) ]
86
103
pub delimiter : u8 ,
87
104
88
105
/// Enable double quote escapes.
89
106
///
90
107
/// This is enabled by default, but it may be disabled. When disabled, quotes in
91
108
/// field data are escaped instead of doubled.
109
+ #[ serde(
110
+ default = "default_double_quote" ,
111
+ skip_serializing_if = "vector_core::serde::skip_serializing_if_default"
112
+ ) ]
92
113
pub double_quote : bool ,
93
114
94
115
/// The escape character to use when writing CSV.
@@ -97,9 +118,18 @@ pub struct CsvSerializerOptions {
97
118
/// like \ (instead of escaping quotes by doubling them).
98
119
///
99
120
/// To use this `double_quotes` needs to be disabled as well otherwise it is ignored
121
+ #[ serde(
122
+ default = "default_escape" ,
123
+ with = "vector_core::serde::ascii_char" ,
124
+ skip_serializing_if = "vector_core::serde::skip_serializing_if_default"
125
+ ) ]
100
126
pub escape : u8 ,
101
127
102
128
/// The quoting style to use when writing CSV data.
129
+ #[ serde(
130
+ default ,
131
+ skip_serializing_if = "vector_core::serde::skip_serializing_if_default"
132
+ ) ]
103
133
pub quote_style : QuoteStyle ,
104
134
105
135
/// Configures the fields that will be encoded, as well as the order in which they
@@ -112,20 +142,8 @@ pub struct CsvSerializerOptions {
112
142
pub fields : Vec < ConfigTargetPath > ,
113
143
}
114
144
115
- impl Default for CsvSerializerOptions {
116
- fn default ( ) -> CsvSerializerOptions {
117
- CsvSerializerOptions {
118
- delimiter : b',' ,
119
- double_quote : true ,
120
- escape : b'"' ,
121
- quote_style : QuoteStyle :: Necessary ,
122
- fields : vec ! [ ] ,
123
- }
124
- }
125
- }
126
-
127
145
impl CsvSerializerOptions {
128
- const fn csv_quote_style ( & self ) -> csv:: QuoteStyle {
146
+ fn csv_quote_style ( & self ) -> csv:: QuoteStyle {
129
147
match self . quote_style {
130
148
QuoteStyle :: Always => csv:: QuoteStyle :: Always ,
131
149
QuoteStyle :: NonNumeric => csv:: QuoteStyle :: NonNumeric ,
0 commit comments