@@ -4,9 +4,8 @@ use crate::config::{ParseOptions, WriteOptions};
44use crate :: error:: { LoftyError , Result } ;
55use crate :: properties:: FileProperties ;
66use crate :: tag:: { Tag , TagExt , TagType } ;
7-
87use crate :: util:: io:: { FileLike , Length , Truncate } ;
9- use std :: fs :: File ;
8+
109use std:: io:: { Read , Seek } ;
1110
1211/// Provides a common interface between [`TaggedFile`] and [`BoundTaggedFile`]
@@ -453,13 +452,13 @@ impl AudioFile for TaggedFile {
453452 }
454453}
455454
456- impl From < BoundTaggedFile > for TaggedFile {
457- fn from ( input : BoundTaggedFile ) -> Self {
455+ impl < F > From < BoundTaggedFile < F > > for TaggedFile {
456+ fn from ( input : BoundTaggedFile < F > ) -> Self {
458457 input. inner
459458 }
460459}
461460
462- /// A variant of [`TaggedFile`] that holds a [`File `] handle , and reflects changes
461+ /// A variant of [`TaggedFile`] that holds a handle to its original [`FileLike `] buffer , and reflects changes
463462/// such as tag removals.
464463///
465464/// For example:
@@ -515,12 +514,27 @@ impl From<BoundTaggedFile> for TaggedFile {
515514/// assert!(!bound_tagged_file.contains_tag_type(TagType::Id3v2));
516515/// # Ok(()) }
517516/// ```
518- pub struct BoundTaggedFile {
519- inner : TaggedFile ,
520- file_handle : File ,
517+ pub struct BoundTaggedFile < F > {
518+ pub ( crate ) inner : TaggedFile ,
519+ pub ( crate ) file_handle : F ,
521520}
522521
523- impl BoundTaggedFile {
522+ impl < F > BoundTaggedFile < F > {
523+ /// Consume this tagged file and return the internal file "buffer".
524+ /// This allows you to reuse the internal file.
525+ ///
526+ /// Any changes that haven't been commited will be discarded once you
527+ /// call this function.
528+ pub fn into_inner ( self ) -> F {
529+ self . file_handle
530+ }
531+ }
532+
533+ impl < F : FileLike > BoundTaggedFile < F >
534+ where
535+ LoftyError : From < <F as Truncate >:: Error > ,
536+ LoftyError : From < <F as Length >:: Error > ,
537+ {
524538 /// Create a new [`BoundTaggedFile`]
525539 ///
526540 /// # Errors
@@ -544,7 +558,7 @@ impl BoundTaggedFile {
544558 /// let bound_tagged_file = BoundTaggedFile::read_from(file, parse_options)?;
545559 /// # Ok(()) }
546560 /// ```
547- pub fn read_from ( mut file : File , parse_options : ParseOptions ) -> Result < Self > {
561+ pub fn read_from ( mut file : F , parse_options : ParseOptions ) -> Result < Self > {
548562 let inner = TaggedFile :: read_from ( & mut file, parse_options) ?;
549563 file. rewind ( ) ?;
550564
@@ -588,18 +602,9 @@ impl BoundTaggedFile {
588602
589603 Ok ( ( ) )
590604 }
591-
592- /// Consume this tagged file and return the internal file "buffer".
593- /// This allows you to reuse the internal file.
594- ///
595- /// Any changes that haven't been commited will be discarded once you
596- /// call this function.
597- pub fn into_inner ( self ) -> File {
598- self . file_handle
599- }
600605}
601606
602- impl TaggedFileExt for BoundTaggedFile {
607+ impl < F > TaggedFileExt for BoundTaggedFile < F > {
603608 fn file_type ( & self ) -> FileType {
604609 self . inner . file_type ( )
605610 }
@@ -633,7 +638,7 @@ impl TaggedFileExt for BoundTaggedFile {
633638 }
634639}
635640
636- impl AudioFile for BoundTaggedFile {
641+ impl < T > AudioFile for BoundTaggedFile < T > {
637642 type Properties = FileProperties ;
638643
639644 fn read_from < R > ( _: & mut R , _: ParseOptions ) -> Result < Self >
0 commit comments