Trait tantivy::Directory [] [src]

pub trait Directory: Debug + Send + Sync + 'static {
    fn open_read(&self, path: &Path) -> Result<ReadOnlySource, OpenReadError>;
fn delete(&self, path: &Path) -> Result<(), DeleteError>;
fn exists(&self, path: &Path) -> bool;
fn open_write(&mut self, path: &Path) -> Result<WritePtr, OpenWriteError>;
fn atomic_read(&self, path: &Path) -> Result<Vec<u8>, OpenReadError>;
fn atomic_write(&mut self, path: &Path, data: &[u8]) -> Result<()>;
fn box_clone(&self) -> Box<Directory>; }

Write-once read many (WORM) abstraction for where tantivy's data should be stored.

There are currently two implementations of Directory

Required Methods

Opens a virtual file for read.

Once a virtual file is open, its data may not change.

Specifically, subsequent writes or flushes should have no effect on the returned ReadOnlySource object.

Removes a file

Removing a file will not affect an eventual existing ReadOnlySource pointing to it.

Removing a nonexistent file, yields a DeleteError::DoesNotExist.

Returns true iff the file exists

Opens a writer for the virtual file associated with a Path.

Right after this call, the file should be created and any subsequent call to open_read for the same path should return a ReadOnlySource.

Write operations may be aggressively buffered. The client of this trait is responsible for calling flush to ensure that subsequent read operations will take into account preceding write operations.

Flush operation should also be persistent.

The user shall not rely on Drop triggering flush. Note that RAMDirectory will panic! if flush was not called.

The file may not previously exist.

Reads the full content file that has been written using atomic_write.

This should only be used for small files.

Atomically replace the content of a file with data.

This calls ensure that reads can never observe a partially written file.

The file may or may not previously exist.

Clones the directory and boxes the clone

Implementors