@@ -23,6 +23,7 @@ use crate::tag::companion_tag::CompanionTag;
2323use crate :: tag:: { Accessor , MergeTag , SplitTag , TagExt , TagType } ;
2424
2525use std:: borrow:: Cow ;
26+ use std:: collections:: HashMap ;
2627use std:: io:: Write ;
2728use std:: ops:: Deref ;
2829
@@ -405,39 +406,51 @@ impl From<crate::tag::Tag> for MatroskaTag {
405406 }
406407}
407408
408- pub ( crate ) struct MatroskaTagRef < ' a , I , S >
409+ pub ( crate ) struct MatroskaTagRef < ' a , I >
409410where
410- I : Iterator < Item = TagRef < ' a , S > > ,
411- S : Iterator < Item = Cow < ' a , SimpleTag < ' a > > > + ' a ,
411+ I : Iterator < Item = TagRef < ' a > > ,
412412{
413- tags : I ,
413+ pub ( crate ) tags : I ,
414414}
415415
416- impl < ' a , I , S > From < & ' a crate :: tag:: Tag > for MatroskaTagRef < ' a , I , S >
417- where
418- I : Iterator < Item = TagRef < ' a , S > > ,
419- S : Iterator < Item = Cow < ' a , SimpleTag < ' a > > > ,
420- {
421- fn from ( _tag : & ' a crate :: tag:: Tag ) -> Self {
422- todo ! ( )
416+ pub ( crate ) fn simple_tags_for_tag ( tag : & crate :: tag:: Tag ) -> impl Iterator < Item = TagRef < ' static > > {
417+ let mut mapped_tags: HashMap < TargetType , Vec < Cow < ' static , SimpleTag < ' static > > > > =
418+ HashMap :: new ( ) ;
419+ for item in & tag. items {
420+ if let Some ( ( simple_tag, target_type) ) = generic:: simple_tag_for_item ( Cow :: Borrowed ( item) ) {
421+ mapped_tags
422+ . entry ( target_type)
423+ . or_default ( )
424+ . push ( Cow :: Owned ( simple_tag) )
425+ }
423426 }
427+
428+ mapped_tags
429+ . into_iter ( )
430+ . map ( |( target_type, simple_tags) | TagRef {
431+ targets : TargetDescriptor :: Basic ( target_type) ,
432+ simple_tags : Box :: new ( simple_tags. into_iter ( ) ) ,
433+ } )
424434}
425435
426- impl < ' a , I , S > MatroskaTagRef < ' a , I , S >
436+ impl < ' a , I > MatroskaTagRef < ' a , I >
427437where
428- I : Iterator < Item = TagRef < ' a , S > > ,
429- S : Iterator < Item = Cow < ' a , SimpleTag < ' a > > > ,
438+ I : Iterator < Item = TagRef < ' a > > ,
430439{
431440 pub ( crate ) fn write_to < F > ( & mut self , _file : & mut F , _write_options : WriteOptions ) -> Result < ( ) >
432441 where
433442 F : FileLike ,
434443 LoftyError : From < <F as Truncate >:: Error > ,
435444 LoftyError : From < <F as Length >:: Error > ,
436445 {
437- todo ! ( )
446+ todo ! ( "Writing matroska tags" )
438447 }
439448
440- fn dump_to < W : Write > ( & self , _writer : & mut W , _write_options : WriteOptions ) -> Result < ( ) > {
441- todo ! ( )
449+ pub ( crate ) fn dump_to < W : Write > (
450+ & self ,
451+ _writer : & mut W ,
452+ _write_options : WriteOptions ,
453+ ) -> Result < ( ) > {
454+ todo ! ( "Dumping matroska tags" )
442455 }
443456}
0 commit comments