From 8bf2898c47cdb291efe1dccbb05174fb10a92c4d Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Thu, 17 Jul 2025 11:33:24 -0400 Subject: [PATCH] Add truncate method to IO trait and Truncate completion variant --- core/io/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/io/mod.rs b/core/io/mod.rs index b58c17ab6..0113db0eb 100644 --- a/core/io/mod.rs +++ b/core/io/mod.rs @@ -19,6 +19,7 @@ pub trait File: Send + Sync { -> Result; fn sync(&self, c: Completion) -> Result; fn size(&self) -> Result; + fn truncate(&self, len: u64, c: Completion) -> Result>; } #[derive(Debug, Copy, Clone, PartialEq)] @@ -53,6 +54,7 @@ pub trait IO: Clock + Send + Sync { pub type Complete = dyn Fn(Arc>, 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, +} + +impl TruncateCompletion { + pub fn new(complete: Box) -> Self { + Self { complete } + } + + pub fn complete(&self, res: i32) { + (self.complete)(res); + } +} + pub type BufferData = Pin>; pub type BufferDropFn = Rc;