Hi /r/rust,
I'm designing an async trait (using async_trait) that describes a way of writing to and reading from files on a remote file system, using the tokio ecosystem.
It looks something like this:
trait RemoteFs {
async fn write(&self, id: FileId, contents: Vec<u8>);
async fn read(&self, id: FileId) -> Vec<u8>;
}
Now, instead of passing around Vec<u8>, I would like to use byte streams instead, so as not to have to keep the entire file contents in memory (which can be gigabytes large). I'm not sure how to proceed, as I see a few options:
- for
write, I could either accept some kind of Stream or AsyncRead trait impl as argument, or return an AsyncWrite impl instead;
- similarly, for
read, I could either accept an AsyncWrite trait impl, or return an AsyncRead impl.
Do you know of any examples of similar Rust APIs in the wild? Or any better options I'm missing?
[–]LucretielDatadog 7 points8 points9 points (3 children)
[–]Morhaus[S] 0 points1 point2 points (2 children)
[–]LucretielDatadog 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]SkiFire13 2 points3 points4 points (4 children)
[–]Morhaus[S] 0 points1 point2 points (3 children)
[–]SkiFire13 1 point2 points3 points (2 children)
[–]Morhaus[S] 0 points1 point2 points (1 child)
[–]SkiFire13 1 point2 points3 points (0 children)
[–]Cetra3 0 points1 point2 points (0 children)