pub struct RecordStore { /* private fields */ }Expand description
A directory of frontmatter record files.
Implementations§
Source§impl RecordStore
impl RecordStore
Sourcepub fn new(dir: impl Into<PathBuf>) -> Self
pub fn new(dir: impl Into<PathBuf>) -> Self
Bind the store to dir; the directory is not touched until a write.
Sourcepub fn list<T: DeserializeOwned + HasName>(&self) -> Result<Vec<RecordFile<T>>>
pub fn list<T: DeserializeOwned + HasName>(&self) -> Result<Vec<RecordFile<T>>>
Every parseable record in the store, sorted by filename.
A missing directory is an empty store, not an error, and files whose
frontmatter is unparseable or carries no name are skipped.
Sourcepub fn list_checked<T: DeserializeOwned + HasName>(
&self,
) -> Result<(Vec<RecordFile<T>>, Vec<String>)>
pub fn list_checked<T: DeserializeOwned + HasName>( &self, ) -> Result<(Vec<RecordFile<T>>, Vec<String>)>
Like RecordStore::list, additionally returning the filenames that
were skipped — unparseable files and files whose frontmatter name is
missing or blank. Callers that must report a broken file use this.
Sourcepub fn get<T: DeserializeOwned + HasName>(
&self,
name: &str,
) -> Result<RecordFile<T>>
pub fn get<T: DeserializeOwned + HasName>( &self, name: &str, ) -> Result<RecordFile<T>>
Look a record up by its frontmatter name.
Sourcepub fn write<T: Serialize + HasName>(
&self,
filename: &str,
value: &T,
body: Option<&str>,
) -> Result<PathBuf>
pub fn write<T: Serialize + HasName>( &self, filename: &str, value: &T, body: Option<&str>, ) -> Result<PathBuf>
Write a new record file, refusing to overwrite an existing one.
Creates the store directory on demand — the lazy rule: only a write makes a directory exist.
Sourcepub fn overwrite<T: Serialize + HasName>(
&self,
filename: &str,
value: &T,
body: Option<&str>,
) -> Result<PathBuf>
pub fn overwrite<T: Serialize + HasName>( &self, filename: &str, value: &T, body: Option<&str>, ) -> Result<PathBuf>
Write a record file, replacing any existing file of the same name.
Sourcepub fn rename_file(
&self,
old_filename: &str,
new_filename: &str,
) -> Result<PathBuf>
pub fn rename_file( &self, old_filename: &str, new_filename: &str, ) -> Result<PathBuf>
Rename a record file in place. The caller is responsible for keeping the
frontmatter name in step (see RecordStore::overwrite).
Sourcepub fn delete_file(&self, filename: &str) -> Result<()>
pub fn delete_file(&self, filename: &str) -> Result<()>
Remove a record file.
Trait Implementations§
Source§impl Clone for RecordStore
impl Clone for RecordStore
Source§impl Debug for RecordStore
impl Debug for RecordStore
impl Eq for RecordStore
Source§impl PartialEq for RecordStore
impl PartialEq for RecordStore
impl StructuralPartialEq for RecordStore
Auto Trait Implementations§
impl Freeze for RecordStore
impl RefUnwindSafe for RecordStore
impl Send for RecordStore
impl Sync for RecordStore
impl Unpin for RecordStore
impl UnsafeUnpin for RecordStore
impl UnwindSafe for RecordStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more