-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create BackupWriter and BackupReader traits for async unit backup
- Loading branch information
Showing
8 changed files
with
91 additions
and
63 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
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
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,34 @@ | ||
use async_trait::async_trait; | ||
use std::io::{Read, Write}; | ||
|
||
|
||
#[async_trait] | ||
/// Write backups to peristent storage. | ||
pub trait BackupWriter { | ||
/// Append new data to the backup. | ||
async fn append(&mut self, data: &[u8]) -> std::io::Result<()>; | ||
} | ||
|
||
#[async_trait] | ||
impl<W: Write + Send> BackupWriter for W { | ||
async fn append(&mut self, data: &[u8]) -> std::io::Result<()> { | ||
self.write_all(data)?; | ||
self.flush() | ||
} | ||
} | ||
|
||
|
||
#[async_trait] | ||
pub trait BackupReader { | ||
/// Read the entire backup. | ||
async fn read(&mut self) -> std::io::Result<Vec<u8>>; | ||
} | ||
|
||
#[async_trait] | ||
impl<R: Read + Send> BackupReader for R { | ||
async fn read(&mut self) -> std::io::Result<Vec<u8>> { | ||
let mut buf = Vec::new(); | ||
self.read_to_end(&mut buf)?; | ||
Ok(buf) | ||
} | ||
} |
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