pub fn get_parent_from_full_path(
full_diary_path: &Path,
) -> Result<&Path, Box<dyn Error>>Expand description
Extracts the parent directory from a file path.
Returns a reference to the parent directory component of the given path. This is useful for creating parent directories before writing a file.
§Arguments
full_diary_path- A file path to extract the parent directory from
§Returns
Ok(&Path)- Reference to the parent directoryErr(Box<dyn Error>)- If the path has no parent (e.g., root directory/)
§Errors
Returns an error if:
- The path is the root directory (has no parent)
- The path is a relative single component with no parent
§Examples
ⓘ
use rusty_commit_saver::vim_commit::get_parent_from_full_path;
use std::path::{Path, PathBuf};
// Normal nested path
let path = Path::new("/home/user/documents/diary.md");
let parent = get_parent_from_full_path(path).unwrap();
assert_eq!(parent, Path::new("/home/user/documents"));
// Deep nesting
let deep = Path::new("/a/b/c/d/e/f/file.txt");
let parent = get_parent_from_full_path(deep).unwrap();
assert_eq!(parent, Path::new("/a/b/c/d/e/f"));
// Root directory fails
let root = Path::new("/");
assert!(get_parent_from_full_path(root).is_err());