From 576ce8fa7f130ff28cd7e9a452f44ac72e395878 Mon Sep 17 00:00:00 2001 From: niluxv Date: Mon, 27 Jan 2020 18:04:17 +0100 Subject: [PATCH 1/2] Fix copy/paste error in "Add `PathBackend` with atomic saves" where `PathDatabase::open` would yield a `FileDatabase` --- src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2c95bea..8433972 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -680,10 +680,12 @@ impl Database { /// Create new [`PathDatabase`] from a [`Path`](std::path::Path). pub fn from_path(path: S, data: Data) - -> error::Result> - where S: AsRef + -> error::Result> + where S: ToOwned, + std::path::PathBuf: std::borrow::Borrow { - let backend = FileBackend::open(path).context(error::RustbreakErrorKind::Backend)?; + let backend = PathBackend::open(path.to_owned()) + .context(error::RustbreakErrorKind::Backend)?; Ok(Database { data: RwLock::new(data), From d12ebf1fc80d6316ec143b859a194f408dbb8f10 Mon Sep 17 00:00:00 2001 From: niluxv Date: Tue, 28 Jan 2020 09:25:01 +0100 Subject: [PATCH 2/2] Advertise `PathDatabase` in crate level documentation --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8433972..4af4904 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,15 +38,19 @@ //! Database. It is then encoded with Ron, Yaml, JSON, Bincode, anything really that uses Serde //! operations! //! -//! There are two helper type aliases `MemoryDatabase` and `FileDatabase`, each backed by their +//! There are three helper type aliases [`MemoryDatabase`], [`FileDatabase`], and [`PathDatabase`], each backed by their //! respective backend. //! -//! The `MemoryBackend` saves its data into a `Vec`, which is not that useful on its own, but +//! The [`MemoryBackend`] saves its data into a `Vec`, which is not that useful on its own, but //! is needed for compatibility with the rest of the Library. //! -//! The `FileDatabase` is a classical file based database. You give it a path or a file, and it +//! The [`FileDatabase`] is a classical file based database. You give it a path or a file, and it //! will use it as its storage. You still get to pick what encoding it uses. //! +//! The [`PathDatabase`] is very similar, but always requires a path for creation. It features atomic +//! saves, so that the old database contents won't be lost when panicing during the save. It +//! should therefore be preferred to a [`FileDatabase`]. +//! //! Using the `with_deser` and `with_backend` one can switch between the representations one needs. //! Even at runtime! However this is only useful in a few scenarios. //!