use async_trait::async_trait;
use futures::executor::block_on;
use std::io::Result;
#[async_trait(?Send)]
pub trait WalrusFile: std::fmt::Debug {
async fn read_at(&self, offset: u64, len: usize) -> Result<Vec<u8>>;
fn read_at_sync(&self, offset: u64, len: usize) -> Result<Vec<u8>> {
block_on(self.read_at(offset, len))
}
async fn write_at(&self, offset: u64, buf: &[u8]) -> Result<usize>;
fn write_at_sync(&self, offset: u64, buf: &[u8]) -> Result<usize> {
block_on(self.write_at(offset, buf))
}
async fn sync_all(&self) -> Result<()>;
fn sync_all_sync(&self) -> Result<()> {
block_on(self.sync_all())
}
async fn len(&self) -> Result<u64>;
fn len_sync(&self) -> Result<u64> {
block_on(self.len())
}
async fn is_empty(&self) -> Result<bool> {
Ok(self.len().await? == 0)
}
}