knowledge-base-crud 0.1.0

Filesystem CRUD operations for a file-based knowledge base
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use crate::Error;
use std::fs;
use std::path::{Path, PathBuf};

pub(crate) fn read(root: &Path, directory: &str, id: &str, extension: &str) -> Result<String, Error> {
    let path = path(root, directory, id, extension);
    fs::read_to_string(&path).map_err(|source| Error::Read { path, source })
}

pub(crate) fn path(root: &Path, directory: &str, id: &str, extension: &str) -> PathBuf {
    root.join(directory).join(Path::new(id).with_extension(extension))
}