@@ -50,7 +50,7 @@ macro_rules! impl_accessor {
50
50
}
51
51
52
52
fn [ <remove_ $name>] ( & mut self ) {
53
- self . remove( & $const)
53
+ let _ = self . remove( & $const) ;
54
54
}
55
55
) +
56
56
}
@@ -142,8 +142,29 @@ impl Ilst {
142
142
}
143
143
144
144
/// Inserts an [`Atom`], replacing any atom with the same [`AtomIdent`]
145
+ ///
146
+ /// # Examples
147
+ ///
148
+ /// ```rust
149
+ /// use lofty::mp4::{Atom, AtomData, AtomIdent, Ilst};
150
+ /// use lofty::Accessor;
151
+ ///
152
+ /// const TITLE_IDENTIFIER: AtomIdent = AtomIdent::Fourcc(*b"\xa9nam");
153
+ ///
154
+ /// let mut ilst = Ilst::new();
155
+ ///
156
+ /// ilst.set_title(String::from("FooBar"));
157
+ /// assert_eq!(ilst.title().as_deref(), Some("FooBar"));
158
+ ///
159
+ /// // Replace our old title
160
+ /// ilst.replace_atom(Atom::new(
161
+ /// TITLE_IDENTIFIER,
162
+ /// AtomData::UTF8(String::from("BarFoo")),
163
+ /// ));
164
+ /// assert_eq!(ilst.title().as_deref(), Some("BarFoo"));
165
+ /// ```
145
166
pub fn replace_atom ( & mut self , atom : Atom < ' _ > ) {
146
- self . remove ( & atom. ident ) ;
167
+ let _ = self . remove ( & atom. ident ) ;
147
168
self . atoms . push ( atom. into_owned ( ) ) ;
148
169
}
149
170
@@ -165,16 +186,24 @@ impl Ilst {
165
186
/// assert!(title.is_some());
166
187
///
167
188
/// // Remove the title
168
- /// ilst.remove(&TITLE_IDENTIFIER);
189
+ /// let returned = ilst.remove(&TITLE_IDENTIFIER);
190
+ /// assert_eq!(returned.count(), 1);
169
191
///
170
192
/// let title = ilst.get(&TITLE_IDENTIFIER);
171
193
/// assert!(title.is_none());
172
194
/// ```
173
- pub fn remove ( & mut self , ident : & AtomIdent < ' _ > ) {
174
- self . atoms
175
- . iter ( )
176
- . position ( |a| & a. ident == ident)
177
- . map ( |p| self . atoms . remove ( p) ) ;
195
+ pub fn remove ( & mut self , ident : & AtomIdent < ' _ > ) -> impl Iterator < Item = Atom < ' static > > + ' _ {
196
+ // TODO: drain_filter
197
+ let mut split_idx = 0_usize ;
198
+
199
+ for read_idx in 0 ..self . atoms . len ( ) {
200
+ if & self . atoms [ read_idx] . ident == ident {
201
+ self . atoms . swap ( split_idx, read_idx) ;
202
+ split_idx += 1 ;
203
+ }
204
+ }
205
+
206
+ self . atoms . drain ( ..split_idx)
178
207
}
179
208
180
209
/// Retain atoms based on the predicate
@@ -316,7 +345,7 @@ impl Accessor for Ilst {
316
345
}
317
346
318
347
fn remove_track ( & mut self ) {
319
- self . remove ( & AtomIdent :: Fourcc ( * b"trkn" ) ) ;
348
+ let _ = self . remove ( & AtomIdent :: Fourcc ( * b"trkn" ) ) ;
320
349
}
321
350
322
351
fn track_total ( & self ) -> Option < u32 > {
@@ -333,7 +362,7 @@ impl Accessor for Ilst {
333
362
334
363
fn remove_track_total ( & mut self ) {
335
364
let track_num = self . track ( ) ;
336
- self . remove ( & AtomIdent :: Fourcc ( * b"trkn" ) ) ;
365
+ let _ = self . remove ( & AtomIdent :: Fourcc ( * b"trkn" ) ) ;
337
366
338
367
if let Some ( track_num) = track_num {
339
368
let track_bytes = ( track_num as u16 ) . to_be_bytes ( ) ;
@@ -356,7 +385,7 @@ impl Accessor for Ilst {
356
385
}
357
386
358
387
fn remove_disk ( & mut self ) {
359
- self . remove ( & AtomIdent :: Fourcc ( * b"disk" ) ) ;
388
+ let _ = self . remove ( & AtomIdent :: Fourcc ( * b"disk" ) ) ;
360
389
}
361
390
362
391
fn disk_total ( & self ) -> Option < u32 > {
@@ -373,7 +402,7 @@ impl Accessor for Ilst {
373
402
374
403
fn remove_disk_total ( & mut self ) {
375
404
let disk_num = self . disk ( ) ;
376
- self . remove ( & AtomIdent :: Fourcc ( * b"disk" ) ) ;
405
+ let _ = self . remove ( & AtomIdent :: Fourcc ( * b"disk" ) ) ;
377
406
378
407
if let Some ( disk_num) = disk_num {
379
408
let disk_bytes = ( disk_num as u16 ) . to_be_bytes ( ) ;
@@ -401,7 +430,7 @@ impl Accessor for Ilst {
401
430
}
402
431
403
432
fn remove_year ( & mut self ) {
404
- self . remove ( & AtomIdent :: Fourcc ( * b"Year" ) ) ;
433
+ let _ = self . remove ( & AtomIdent :: Fourcc ( * b"Year" ) ) ;
405
434
}
406
435
}
407
436
0 commit comments