Struct rustbreak::backend::PathBackend
source · [−]pub struct PathBackend { /* private fields */ }
Expand description
A Backend
using a file given the path.
Features atomic saves, so that the database file won’t be corrupted or deleted if the program panics during the save.
Implementations
sourceimpl PathBackend
impl PathBackend
sourcepub fn from_path_or_fail(path: PathBuf) -> BackendResult<Self>
pub fn from_path_or_fail(path: PathBuf) -> BackendResult<Self>
Opens a new PathBackend
for a given path.
Errors when the file doesn’t yet exist.
sourcepub fn from_path_or_create(path: PathBuf) -> BackendResult<(Self, bool)>
pub fn from_path_or_create(path: PathBuf) -> BackendResult<(Self, bool)>
Opens a new PathBackend
for a given path.
Creates a file if it doesn’t yet exist.
Returns the PathBackend
and whether the file already existed.
sourcepub fn from_path_or_create_and<C>(
path: PathBuf,
closure: C
) -> BackendResult<Self> where
C: FnOnce(&mut File),
pub fn from_path_or_create_and<C>(
path: PathBuf,
closure: C
) -> BackendResult<Self> where
C: FnOnce(&mut File),
Opens a new PathBackend
for a given path.
Creates a file if it doesn’t yet exist, and calls closure
with it.
Trait Implementations
sourceimpl Backend for PathBackend
impl Backend for PathBackend
sourcefn put_data(&mut self, data: &[u8]) -> BackendResult<()>
fn put_data(&mut self, data: &[u8]) -> BackendResult<()>
Write the byte slice to the backend. This uses and atomic save.
This won’t corrupt the existing database file if the program panics during the save.
sourcefn get_data(&mut self) -> BackendResult<Vec<u8>>
fn get_data(&mut self) -> BackendResult<Vec<u8>>
Read the all data from the backend.
Auto Trait Implementations
impl RefUnwindSafe for PathBackend
impl Send for PathBackend
impl Sync for PathBackend
impl Unpin for PathBackend
impl UnwindSafe for PathBackend
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more