mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-22 08:25:29 +01:00
Add truncate method to IO trait and Truncate completion variant
This commit is contained in:
@@ -19,6 +19,7 @@ pub trait File: Send + Sync {
|
||||
-> Result<Completion>;
|
||||
fn sync(&self, c: Completion) -> Result<Completion>;
|
||||
fn size(&self) -> Result<u64>;
|
||||
fn truncate(&self, len: u64, c: Completion) -> Result<Arc<Completion>>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
@@ -53,6 +54,7 @@ pub trait IO: Clock + Send + Sync {
|
||||
pub type Complete = dyn Fn(Arc<RefCell<Buffer>>, i32);
|
||||
pub type WriteComplete = dyn Fn(i32);
|
||||
pub type SyncComplete = dyn Fn(i32);
|
||||
pub type TruncateComplete = dyn Fn(i32);
|
||||
|
||||
#[must_use]
|
||||
#[derive(Clone)]
|
||||
@@ -69,6 +71,7 @@ pub enum CompletionType {
|
||||
Read(ReadCompletion),
|
||||
Write(WriteCompletion),
|
||||
Sync(SyncCompletion),
|
||||
Truncate(TruncateCompletion),
|
||||
}
|
||||
|
||||
pub struct ReadCompletion {
|
||||
@@ -122,6 +125,7 @@ impl Completion {
|
||||
CompletionType::Read(r) => r.complete(result),
|
||||
CompletionType::Write(w) => w.complete(result),
|
||||
CompletionType::Sync(s) => s.complete(result), // fix
|
||||
CompletionType::Truncate(t) => t.complete(result),
|
||||
};
|
||||
self.inner.is_completed.set(true);
|
||||
}
|
||||
@@ -191,6 +195,20 @@ impl SyncCompletion {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TruncateCompletion {
|
||||
pub complete: Box<TruncateComplete>,
|
||||
}
|
||||
|
||||
impl TruncateCompletion {
|
||||
pub fn new(complete: Box<TruncateComplete>) -> Self {
|
||||
Self { complete }
|
||||
}
|
||||
|
||||
pub fn complete(&self, res: i32) {
|
||||
(self.complete)(res);
|
||||
}
|
||||
}
|
||||
|
||||
pub type BufferData = Pin<Vec<u8>>;
|
||||
|
||||
pub type BufferDropFn = Rc<dyn Fn(BufferData)>;
|
||||
|
||||
Reference in New Issue
Block a user