@@ -31,13 +31,13 @@ impl<'borrow, 'lookup, 'event> MutableValue<'borrow, 'lookup, 'event> {
31
31
/// the Value event(s) are replaced with a single new event containing the
32
32
/// new value.
33
33
pub fn set_string ( & mut self , input : impl AsRef < str > ) {
34
- self . set_bytes ( input. as_ref ( ) . into ( ) ) ;
34
+ self . set ( input. as_ref ( ) . into ( ) ) ;
35
35
}
36
36
37
37
/// Update the value to the provided one. This modifies the value such that
38
38
/// the Value event(s) are replaced with a single new event containing the
39
39
/// new value.
40
- pub fn set_bytes ( & mut self , input : & BStr ) {
40
+ pub fn set ( & mut self , input : & BStr ) {
41
41
if self . size . 0 > 0 {
42
42
self . section . delete ( self . index , self . index + self . size ) ;
43
43
}
@@ -132,25 +132,16 @@ impl<'borrow, 'lookup, 'event> MutableMultiValue<'borrow, 'lookup, 'event> {
132
132
/// # Safety
133
133
///
134
134
/// This will panic if the index is out of range.
135
- pub fn set_string ( & mut self , index : usize , input : String ) {
136
- self . set_bytes ( index, input) ;
135
+ pub fn set_string_at ( & mut self , index : usize , input : impl AsRef < str > ) {
136
+ self . set_at ( index, input. as_ref ( ) . into ( ) ) ;
137
137
}
138
138
139
139
/// Sets the value at the given index.
140
140
///
141
141
/// # Safety
142
142
///
143
143
/// This will panic if the index is out of range.
144
- pub fn set_bytes ( & mut self , index : usize , input : impl Into < BString > ) {
145
- self . set_value ( index, Cow :: Owned ( input. into ( ) ) ) ;
146
- }
147
-
148
- /// Sets the value at the given index.
149
- ///
150
- /// # Safety
151
- ///
152
- /// This will panic if the index is out of range.
153
- pub fn set_value ( & mut self , index : usize , input : Cow < ' event , BStr > ) {
144
+ pub fn set_at ( & mut self , index : usize , input : & BStr ) {
154
145
let EntryData {
155
146
section_id,
156
147
offset_index,
@@ -172,7 +163,7 @@ impl<'borrow, 'lookup, 'event> MutableMultiValue<'borrow, 'lookup, 'event> {
172
163
/// remaining values are ignored.
173
164
///
174
165
/// [`zip`]: std::iter::Iterator::zip
175
- pub fn set_values ( & mut self , input : impl IntoIterator < Item = Cow < ' event , BStr > > ) {
166
+ pub fn set_values < ' a > ( & mut self , input : impl IntoIterator < Item = & ' a BStr > ) {
176
167
for (
177
168
EntryData {
178
169
section_id,
@@ -192,39 +183,14 @@ impl<'borrow, 'lookup, 'event> MutableMultiValue<'borrow, 'lookup, 'event> {
192
183
}
193
184
}
194
185
195
- /// Sets all values in this multivar to the provided one by copying the
196
- /// `input` string to all values.
197
- pub fn set_str_all ( & mut self , input : & str ) {
198
- self . set_owned_values_all ( input) ;
199
- }
200
-
201
- /// Sets all values in this multivar to the provided one by copying the
202
- /// `input` bytes to all values.
203
- pub fn set_owned_values_all < ' a > ( & mut self , input : impl Into < & ' a BStr > ) {
204
- let input = input. into ( ) ;
205
- for EntryData {
206
- section_id,
207
- offset_index,
208
- } in & self . indices_and_sizes
209
- {
210
- Self :: set_value_inner (
211
- & self . key ,
212
- & mut self . offsets ,
213
- self . section . get_mut ( section_id) . expect ( "known section id" ) ,
214
- * section_id,
215
- * offset_index,
216
- Cow :: Owned ( input. to_owned ( ) ) ,
217
- ) ;
218
- }
219
- }
220
-
221
186
/// Sets all values in this multivar to the provided one without owning the
222
187
/// provided input. Consider using [`Self::set_owned_values_all`] or
223
188
/// [`Self::set_str_all`] unless you have a strict performance or memory
224
189
/// need for a more ergonomic interface.
225
190
///
226
191
/// [`File`]: crate::File
227
- pub fn set_values_all ( & mut self , input : & ' event BStr ) {
192
+ pub fn set_all < ' a > ( & mut self , input : impl Into < & ' a BStr > ) {
193
+ let input = input. into ( ) ;
228
194
for EntryData {
229
195
section_id,
230
196
offset_index,
@@ -236,7 +202,7 @@ impl<'borrow, 'lookup, 'event> MutableMultiValue<'borrow, 'lookup, 'event> {
236
202
self . section . get_mut ( section_id) . expect ( "known section id" ) ,
237
203
* section_id,
238
204
* offset_index,
239
- Cow :: Borrowed ( input) ,
205
+ input,
240
206
) ;
241
207
}
242
208
}
@@ -247,7 +213,7 @@ impl<'borrow, 'lookup, 'event> MutableMultiValue<'borrow, 'lookup, 'event> {
247
213
section : & mut SectionBody < ' event > ,
248
214
section_id : SectionBodyId ,
249
215
offset_index : usize ,
250
- value : Cow < ' a , BStr > ,
216
+ value : & BStr ,
251
217
) {
252
218
let ( offset, size) = MutableMultiValue :: index_and_size ( offsets, section_id, offset_index) ;
253
219
let whitespace: Whitespace < ' _ > = ( & * section) . into ( ) ;
@@ -256,7 +222,7 @@ impl<'borrow, 'lookup, 'event> MutableMultiValue<'borrow, 'lookup, 'event> {
256
222
257
223
let key_sep_events = whitespace. key_value_separators ( ) ;
258
224
MutableMultiValue :: set_offset ( offsets, section_id, offset_index, 2 + key_sep_events. len ( ) ) ;
259
- section. insert ( offset, Event :: Value ( escape_value ( value. as_ref ( ) ) . into ( ) ) ) ;
225
+ section. insert ( offset, Event :: Value ( escape_value ( value) . into ( ) ) ) ;
260
226
section. insert_many ( offset, key_sep_events. into_iter ( ) . rev ( ) ) ;
261
227
section. insert ( offset, Event :: SectionKey ( key. to_owned ( ) ) ) ;
262
228
}
0 commit comments