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, result};
19
20mod config;
21mod note;
22mod vault;
23
24pub use config::ObsidianConfig;
25pub use note::Note;
26pub use vault::Vault;
27
28/// A [`std::result::Result`] type for fallible operations in [`crate::obsidian`].
29///
30/// For convenience of use and to avoid writing [`Error`] directly.
31/// All fallible operations return [`Error`] as the error variant.
32///
33/// # Examples
34///
35/// ```
36/// use std::path::Path;
37/// use basalt_core::obsidian::{ObsidianConfig, Error};
38///
39///
40/// let config_result = ObsidianConfig::load_from(Path::new("./nonexistent"));
41/// assert_eq!(config_result.is_err(), true);
42/// ```
43pub type Result<T> = result::Result<T, Error>;
44
45/// Error type for fallible operations in this [`crate`].
46///
47/// Implements [`std::error::Error`] via [thiserror](https://docs.rs/thiserror).
48#[derive(thiserror::Error, Debug)]
49pub enum Error {
50 /// Expected resource behind a path was not found.
51 #[error("Path not found: {0}")]
52 PathNotFound(String),
53
54 /// JSON (de)serialization error, from [`serde_json::Error`].
55 #[error("JSON (de)serialization error: {0}")]
56 Json(#[from] serde_json::Error),
57
58 /// I/O error, from [`std::io::Error`].
59 #[error("I/O error: {0}")]
60 Io(#[from] io::Error),
61}