@@ -23,6 +23,7 @@ use crate::tag::companion_tag::CompanionTag;
23
23
use crate :: tag:: { Accessor , MergeTag , SplitTag , TagExt , TagType } ;
24
24
25
25
use std:: borrow:: Cow ;
26
+ use std:: collections:: HashMap ;
26
27
use std:: io:: Write ;
27
28
use std:: ops:: Deref ;
28
29
@@ -405,39 +406,51 @@ impl From<crate::tag::Tag> for MatroskaTag {
405
406
}
406
407
}
407
408
408
- pub ( crate ) struct MatroskaTagRef < ' a , I , S >
409
+ pub ( crate ) struct MatroskaTagRef < ' a , I >
409
410
where
410
- I : Iterator < Item = TagRef < ' a , S > > ,
411
- S : Iterator < Item = Cow < ' a , SimpleTag < ' a > > > + ' a ,
411
+ I : Iterator < Item = TagRef < ' a > > ,
412
412
{
413
- tags : I ,
413
+ pub ( crate ) tags : I ,
414
414
}
415
415
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
+ }
423
426
}
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
+ } )
424
434
}
425
435
426
- impl < ' a , I , S > MatroskaTagRef < ' a , I , S >
436
+ impl < ' a , I > MatroskaTagRef < ' a , I >
427
437
where
428
- I : Iterator < Item = TagRef < ' a , S > > ,
429
- S : Iterator < Item = Cow < ' a , SimpleTag < ' a > > > ,
438
+ I : Iterator < Item = TagRef < ' a > > ,
430
439
{
431
440
pub ( crate ) fn write_to < F > ( & mut self , _file : & mut F , _write_options : WriteOptions ) -> Result < ( ) >
432
441
where
433
442
F : FileLike ,
434
443
LoftyError : From < <F as Truncate >:: Error > ,
435
444
LoftyError : From < <F as Length >:: Error > ,
436
445
{
437
- todo ! ( )
446
+ todo ! ( "Writing matroska tags" )
438
447
}
439
448
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" )
442
455
}
443
456
}
0 commit comments