core/io: add the finish() and new_read_boxed() to FileReader
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 20 Oct 2021 16:26:46 +0000 (18:26 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 20 Oct 2021 16:26:46 +0000 (18:26 +0200)
nihav-core/src/io/byteio.rs

index a194e657678dd12cbcf88ad9a383bc18cdb5de2f..3fbee946a8989872a784adda451e6940582e7519 100644 (file)
@@ -557,6 +557,12 @@ impl<T: Read+Seek> FileReader<T> {
     pub fn new_read(file: T) -> Self {
         FileReader { file: Box::new(file), eof : false }
     }
+    /// Constructs a new instance of `FileReader` using a boxed resource.
+    pub fn new_read_boxed(file: Box<T>) -> Self {
+        FileReader { file, eof : false }
+    }
+    /// Destroys the reader and releases the reader resource for a further use.
+    pub fn finish(self) -> Box<T> { self.file }
 }
 
 impl<T: Read+Seek> ByteIO for FileReader<T> {