-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,187 additions
and
90 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 |
---|---|---|
@@ -1,16 +1,42 @@ | ||
#[cfg(any(feature = "tokio", test))] | ||
pub mod tokio; | ||
|
||
use std::{future::Future, io, path::Path}; | ||
use std::{ | ||
fmt::{Display, Formatter}, | ||
future::Future, | ||
io, | ||
path::Path, | ||
}; | ||
|
||
use futures_io::{AsyncRead, AsyncSeek, AsyncWrite}; | ||
use ulid::Ulid; | ||
|
||
pub trait AsyncFile: AsyncRead + AsyncWrite + AsyncSeek + Send + Unpin + 'static {} | ||
pub(crate) type FileId = Ulid; | ||
|
||
impl<T> AsyncFile for T where T: AsyncRead + AsyncWrite + AsyncSeek + Send + Unpin + 'static {} | ||
pub enum FileType { | ||
WAL, | ||
PARQUET, | ||
LOG, | ||
} | ||
|
||
pub trait AsyncFile: AsyncRead + AsyncWrite + AsyncSeek + Send + Sync + Unpin + 'static {} | ||
|
||
impl<T> AsyncFile for T where T: AsyncRead + AsyncWrite + AsyncSeek + Send + Sync + Unpin + 'static {} | ||
|
||
pub trait Fs { | ||
type File: AsyncFile; | ||
|
||
fn open(&self, path: impl AsRef<Path>) -> impl Future<Output = io::Result<Self::File>>; | ||
fn open(path: impl AsRef<Path>) -> impl Future<Output = io::Result<Self::File>>; | ||
|
||
fn remove(path: impl AsRef<Path>) -> impl Future<Output = io::Result<()>>; | ||
} | ||
|
||
impl Display for FileType { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
FileType::WAL => write!(f, "wal"), | ||
FileType::PARQUET => write!(f, "parquet"), | ||
FileType::LOG => write!(f, "log"), | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,21 @@ | ||
use std::{io, path::Path}; | ||
|
||
use tokio::fs::{remove_file, File}; | ||
use tokio_util::compat::{Compat, TokioAsyncReadCompatExt}; | ||
|
||
use super::Fs; | ||
use crate::executor::tokio::TokioExecutor; | ||
|
||
pub struct TokioFs; | ||
impl Fs for TokioExecutor { | ||
type File = Compat<File>; | ||
|
||
impl Fs for TokioFs { | ||
type File = Compat<tokio::fs::File>; | ||
|
||
async fn open(&self, path: impl AsRef<Path>) -> io::Result<Self::File> { | ||
tokio::fs::File::create_new(path) | ||
async fn open(path: impl AsRef<Path>) -> io::Result<Self::File> { | ||
File::create_new(path) | ||
.await | ||
.map(TokioAsyncReadCompatExt::compat) | ||
} | ||
|
||
async fn remove(path: impl AsRef<Path>) -> io::Result<()> { | ||
remove_file(path).await | ||
} | ||
} |
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
Oops, something went wrong.