basalt_core/
obsidian.rs

1//! This module provides functionality operating with Obsidian. It lets you read and manipulate
2//! Obsidian's configuration, vaults, and notes.
3//!
4//! Currently supports reading vaults, notes, and writing to note path.
5//!
6//! # Example
7//!
8//! ```
9//! use basalt_core::obsidian::{ObsidianConfig, Error, Vault};
10//!
11//! let config = ObsidianConfig::from([
12//!   ("Obsidian", Vault::default()),
13//!   ("My Vault", Vault::default()),
14//! ]);
15//!
16//! _ = config.get_vault_by_name("Obsidian");
17//! ```
18use std::{io, path::PathBuf, result};
19
20mod config;
21mod note;
22mod vault;
23mod vault_entry;
24
25pub use config::ObsidianConfig;
26pub use note::Note;
27pub use vault::Vault;
28pub use vault_entry::FindNote;
29pub use vault_entry::VaultEntry;
30
31/// A [`std::result::Result`] type for fallible operations in [`crate::obsidian`].
32///
33/// For convenience of use and to avoid writing [`Error`] directly.
34/// All fallible operations return [`Error`] as the error variant.
35///
36/// # Examples
37///
38/// ```
39/// use std::path::Path;
40/// use basalt_core::obsidian::{ObsidianConfig, Error};
41///
42///
43/// let config_result = ObsidianConfig::load_from(Path::new("./nonexistent"));
44/// assert_eq!(config_result.is_err(), true);
45/// ```
46pub type Result<T> = result::Result<T, Error>;
47
48/// Error type for fallible operations in this [`crate`].
49///
50/// Implements [`std::error::Error`] via [thiserror](https://docs.rs/thiserror).
51#[derive(thiserror::Error, Debug)]
52pub enum Error {
53    /// Expected resource behind a path was not found.
54    #[error("Path not found: {0}")]
55    PathNotFound(String),
56
57    /// Filename was empty
58    #[error("Empty filename for path: {0}")]
59    EmptyFileName(PathBuf),
60
61    /// JSON (de)serialization error, from [`serde_json::Error`].
62    #[error("JSON (de)serialization error: {0}")]
63    Json(#[from] serde_json::Error),
64
65    /// I/O error, from [`std::io::Error`].
66    #[error("I/O error: {0}")]
67    Io(#[from] io::Error),
68}