pub struct FSRepo {
pub base_dir: PathBuf,
pub config: Config,
pub git_repo: GitRepo,
}
Expand description
Filesystem-backed implementation of SnippetRepository
.
Snippets are stored under a root base_dir
, each in a dedicated subdirectory named by slug.
Each snippet directory contains:
meta.toml
: metadata (name, tags, language, etc.)content.<ext>
: raw snippet content file Additionally,base_dir
contains:snippets/
: all snippet foldershistory/
: reserved for future versioning/history featuresconfig.toml
: configuration file (created if missing)
Fields§
§base_dir: PathBuf
Root directory containing all snippet data.
config: Config
§git_repo: GitRepo
Implementations§
Source§impl FSRepo
impl FSRepo
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<Self, NibbError>
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, NibbError>
Creates a new FSRepo
and ensures the necessary folder structure exists.
Will create snippets/
, history/
, and config.toml
if missing.
Sourcepub fn snippet_path(&self, slug: &str) -> PathBuf
pub fn snippet_path(&self, slug: &str) -> PathBuf
Returns the path to a snippet’s directory based on its slug.
Trait Implementations§
Source§impl SnippetRepository for FSRepo
impl SnippetRepository for FSRepo
Source§fn load_all(&self) -> Result<Vec<Snippet>, NibbError>
fn load_all(&self) -> Result<Vec<Snippet>, NibbError>
Loads all snippets by iterating through the snippets/
directory
and deserializing each snippet from meta.toml
and its content file.
Source§fn load(&self, slug: &str) -> Result<Snippet, NibbError>
fn load(&self, slug: &str) -> Result<Snippet, NibbError>
Loads a specific snippet by slug.
Reads metadata from meta.toml
and content from content.<ext>
.
Source§fn save(&self, snippet: &Snippet) -> Result<(), NibbError>
fn save(&self, snippet: &Snippet) -> Result<(), NibbError>
Saves a single snippet to disk.
Creates the snippet folder and both metadata/content files if they don’t exist.
Auto Trait Implementations§
impl Freeze for FSRepo
impl RefUnwindSafe for FSRepo
impl Send for FSRepo
impl !Sync for FSRepo
impl Unpin for FSRepo
impl UnwindSafe for FSRepo
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
Mutably borrows from an owned value. Read more