Skip to main content

FileHandle

Struct FileHandle 

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

A file handle with latch protection for thread-safe I/O.

The handle holds a file descriptor and an exclusive latch. All I/O operations must be performed while holding the latch.

Implementations§

Source§

impl FileHandle

Source

pub fn new(file_num: u32) -> Self

Creates a new uninitialized file handle.

The file must be initialized via init() before use.

Source

pub fn init(&mut self, file: File, log_version: u32)

Initializes the handle with an open file and log version.

Source

pub fn file_num(&self) -> u32

Returns the file number.

Source

pub fn log_version(&self) -> u32

Returns the log version.

Source

pub fn is_initialized(&self) -> bool

Returns true if the file is initialized.

Source

pub fn acquire(&self) -> Result<FileHandleGuard<'_>>

Acquires the latch and returns a guard that provides access to the file.

Returns Ok(guard) on success, or Err(LogError::LatchTimeout) if the latch acquisition times out. The latch is released when the guard drops.

Source

pub fn try_acquire(&self) -> Option<FileHandleGuard<'_>>

Attempts to acquire the latch without blocking.

Returns None if the latch is currently held.

Source

pub fn close(&mut self) -> Result<()>

Closes the file handle.

This should only be called when the handle is no longer in use.

Trait Implementations§

Source§

impl Drop for FileHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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, 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, 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.