forked from LaurentMazare/tch-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Read+Seek trait and Write trait support (LaurentMazare#441)
* Add APIs to read/write rust streams. * Fix inverted dependency. * Refactor similar functions. * Run cargo fmt. * Make ReadStream private. * Drop explicitly. * Fix some clippy lint. * Run cargo fmt.
- Loading branch information
1 parent
2cce902
commit 6fd63d8
Showing
10 changed files
with
522 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::io::{Read, Result, Seek, SeekFrom}; | ||
use torch_sys::io::ReadStream; | ||
|
||
pub struct ReadSeekAdapter<T> { | ||
inner: T, | ||
} | ||
|
||
impl<T: Read + Seek> ReadSeekAdapter<T> { | ||
pub fn new(inner: T) -> Self { | ||
Self { inner } | ||
} | ||
} | ||
|
||
impl<T: Read> Read for ReadSeekAdapter<T> { | ||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> { | ||
self.inner.read(buf) | ||
} | ||
} | ||
|
||
impl<T: Seek> Seek for ReadSeekAdapter<T> { | ||
fn seek(&mut self, pos: SeekFrom) -> Result<u64> { | ||
self.inner.seek(pos) | ||
} | ||
} | ||
|
||
impl<T: Read + Seek> ReadStream for ReadSeekAdapter<T> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.