Skip to main content

OpenFile

Struct OpenFile 

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

One open file handle serving positioned reads of a local plaintext file.

Opening reads no content: a local file’s current bytes are the answer to a read of it, and the one place a blob’s bytes are checked against the hash its row declares is publication, where they become canonical synced content. A read here is a read.

The handle is held for the reader’s life rather than reopened per range, and that is a property, not an optimization: a path can be replaced between two reads, a descriptor cannot, so every range comes from the one file that was opened even if it is later evicted, renamed, or replaced.

Each read positions the descriptor itself, and the mutex makes that seek and its read one operation, so concurrent readers of one handle cannot interleave into each other’s ranges.

Implementations§

Source§

impl OpenFile

Source

pub async fn open(path: &Path) -> Result<Self, FileError>

Open path and stat it for the length its reads are bounded by.

Source

pub fn size(&self) -> u64

Source

pub async fn read_at(&self, offset: u64, len: u64) -> Result<Vec<u8>, FileError>

Read exactly len bytes at offset. The caller bounds the range against size; a file that cannot supply them is an error, never a short result.

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.

§

impl<T> Instrument for T

§

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

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

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> 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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