basalt_core/obsidian/
note.rs1use std::path::{Path, PathBuf};
3
4use crate::obsidian::Error;
5
6#[derive(Debug, Clone, PartialEq, Default)]
8pub struct Note {
9 name: String,
10 path: PathBuf,
11}
12
13impl Note {
14 pub fn name(&self) -> &str {
16 &self.name
17 }
18
19 pub fn path(&self) -> &Path {
21 &self.path
22 }
23}
24
25impl TryFrom<(&str, PathBuf)> for Note {
26 type Error = Error;
27 fn try_from((name, path): (&str, PathBuf)) -> Result<Self, Self::Error> {
28 match path.is_file() {
29 true => Ok(Self {
30 name: name.to_string(),
31 path,
32 }),
33 false => Err(Error::Io(std::io::ErrorKind::IsADirectory.into())),
34 }
35 }
36}
37
38impl TryFrom<(String, PathBuf)> for Note {
39 type Error = Error;
40 fn try_from((name, path): (String, PathBuf)) -> Result<Self, Self::Error> {
41 Self::try_from((name.as_str(), path))
42 }
43}
44
45impl Note {
46 pub fn new_unchecked(name: &str, path: &Path) -> Self {
50 Self {
51 name: name.to_string(),
52 path: path.to_path_buf(),
53 }
54 }
55}