@@ -421,22 +421,26 @@ impl SplitTag for ApeTag {
421421
422422 let mut tag = Tag :: new ( TagType :: Ape ) ;
423423
424- for item in std:: mem:: take ( & mut self . items ) {
425- let item_key = ItemKey :: from_key ( TagType :: Ape , item. key ( ) ) ;
424+ self . items . retain_mut ( |item| {
425+ let Some ( item_key) = ItemKey :: from_key ( TagType :: Ape , item. key ( ) ) else {
426+ return true ;
427+ } ;
426428
427429 // The text pairs need some special treatment
428430 match ( item_key, item. value ( ) ) {
429431 ( ItemKey :: TrackNumber | ItemKey :: TrackTotal , ItemValue :: Text ( val) )
430432 if split_pair ( val, & mut tag, ItemKey :: TrackNumber , ItemKey :: TrackTotal )
431433 . is_some ( ) =>
432434 {
433- continue ; // Item consumed
435+ * item = ApeItem :: EMPTY ;
436+ false // Item consumed
434437 } ,
435438 ( ItemKey :: DiscNumber | ItemKey :: DiscTotal , ItemValue :: Text ( val) )
436439 if split_pair ( val, & mut tag, ItemKey :: DiscNumber , ItemKey :: DiscTotal )
437440 . is_some ( ) =>
438441 {
439- continue ; // Item consumed
442+ * item = ApeItem :: EMPTY ;
443+ false // Item consumed
440444 } ,
441445 ( ItemKey :: MovementNumber | ItemKey :: MovementTotal , ItemValue :: Text ( val) )
442446 if split_pair (
@@ -447,13 +451,16 @@ impl SplitTag for ApeTag {
447451 )
448452 . is_some ( ) =>
449453 {
450- continue ; // Item consumed
454+ * item = ApeItem :: EMPTY ;
455+ false // Item consumed
451456 } ,
452457 ( k, _) => {
458+ let item = std:: mem:: replace ( item, ApeItem :: EMPTY ) ;
453459 tag. items . push ( TagItem :: new ( k, item. value ) ) ;
460+ false // Item consumed
454461 } ,
455462 }
456- }
463+ } ) ;
457464
458465 ( SplitTagRemainder ( self ) , tag)
459466 }
@@ -541,22 +548,22 @@ pub(crate) fn tagitems_into_ape(tag: &Tag) -> impl Iterator<Item = ApeItemRef<'_
541548 }
542549
543550 tag. items ( )
544- . filter ( |item| !NUMBER_PAIR_KEYS . contains ( item. key ( ) ) )
551+ . filter ( |item| !NUMBER_PAIR_KEYS . contains ( & item. key ( ) ) )
545552 . filter_map ( |i| {
546- i. key ( ) . map_key ( TagType :: Ape , true ) . map ( |key| ApeItemRef {
553+ i. key ( ) . map_key ( TagType :: Ape ) . map ( |key| ApeItemRef {
547554 read_only : false ,
548555 key,
549556 value : ( & i. item_value ) . into ( ) ,
550557 } )
551558 } )
552559 . chain ( create_apeitemref_for_number_pair (
553- tag. get_string ( & ItemKey :: TrackNumber ) ,
554- tag. get_string ( & ItemKey :: TrackTotal ) ,
560+ tag. get_string ( ItemKey :: TrackNumber ) ,
561+ tag. get_string ( ItemKey :: TrackTotal ) ,
555562 "Track" ,
556563 ) )
557564 . chain ( create_apeitemref_for_number_pair (
558- tag. get_string ( & ItemKey :: DiscNumber ) ,
559- tag. get_string ( & ItemKey :: DiscTotal ) ,
565+ tag. get_string ( ItemKey :: DiscNumber ) ,
566+ tag. get_string ( ItemKey :: DiscTotal ) ,
560567 "Disk" ,
561568 ) )
562569}
0 commit comments