Skip to main content

PositionedDiskWriter

Struct PositionedDiskWriter 

Source
pub struct PositionedDiskWriter { /* private fields */ }
Expand description

A disk writer that performs positioned (offset-based) I/O via OS-native pwrite/seek_write syscalls.

The file descriptor is protected by a std::sync::Mutex held only for the duration of each synchronous syscall — never across .await points. This enables true concurrency for non-overlapping writes when multiple writers reference the same file.

Uses std::fs::File (not tokio::fs::File) because FileExt::write_at is a synchronous method available only on std::fs::File. Since pwrite is a fast non-blocking syscall (it never waits on async I/O completion), running it synchronously inside a tokio task is acceptable — it does not stall the runtime for meaningful durations.

Implementations§

Source§

impl PositionedDiskWriter

Source

pub fn new(path: &Path, total_size: Option<u64>) -> Self

Create a new PositionedDiskWriter for the given path.

If total_size is provided and the file is newly created (size 0), the file is pre-allocated to total_size bytes on first open. This avoids fragmentation and enables concurrent writes to arbitrary offsets without per-write file extension.

Source

pub fn total_size(&self) -> Option<u64>

Returns the configured total size, if any.

Source

pub fn raw_fd(&self) -> Option<RawFd>

Returns the raw file descriptor of the underlying file, if open.

This is used by the Linux splice download path to obtain the file fd for splice(2) zero-copy transfer. Returns None if the file has not been opened yet (caller should call open() first).

The caller must ensure the writer is not dropped or closed while the returned fd is in use. The fd is valid only while the writer holds the file open.

Trait Implementations§

Source§

impl SeekableDiskWriter for PositionedDiskWriter

Source§

fn write_bytes_at<'life0, 'async_trait>( &'life0 mut self, offset: u64, data: Bytes, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Zero-copy write: accepts Bytes directly. Since pwrite takes &[u8], we simply dereference the Bytes (no copy — Bytes derefs to [u8]).

Source§

fn open<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn write_at<'life0, 'life1, 'async_trait>( &'life0 mut self, offset: u64, data: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn read_at<'life0, 'life1, 'async_trait>( &'life0 mut self, offset: u64, buf: &'life1 mut [u8], ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn truncate<'life0, 'async_trait>( &'life0 mut self, length: u64, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn flush<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn len<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn path(&self) -> &Path

Source§

fn close<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Close the writer and release underlying file resources. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more