pub mod note_aliases;
pub mod note_default;
pub mod note_in_memory;
pub mod note_is_todo;
pub mod note_on_disk;
pub mod note_once_cell;
pub mod note_once_lock;
pub mod note_read;
pub mod note_tags;
pub mod parser;
#[cfg(not(target_family = "wasm"))]
pub mod note_write;
use std::{borrow::Cow, collections::HashMap, fs::OpenOptions, path::Path};
pub use note_default::NoteDefault;
pub use note_read::{NoteFromReader, NoteFromString};
#[cfg(not(target_family = "wasm"))]
pub use note_read::NoteFromFile;
#[cfg(not(target_family = "wasm"))]
pub use note_write::NoteWrite;
pub(crate) type DefaultProperties = HashMap<String, serde_yml::Value>;
pub trait Note: Sized {
type Properties: Clone;
type Error: std::error::Error;
fn properties(&self) -> Result<Option<Cow<'_, Self::Properties>>, Self::Error>;
fn content(&self) -> Result<Cow<'_, str>, Self::Error>;
fn path(&self) -> Option<Cow<'_, Path>>;
fn note_name(&self) -> Option<String> {
self.path().as_ref().map(|path| {
path.file_stem()
.expect("Path is not file")
.to_string_lossy()
.to_string()
})
}
fn count_words_from_content(&self) -> Result<usize, Self::Error> {
let content = self.content()?;
Ok(content.split_whitespace().count())
}
fn count_symbols_from_content(&self) -> Result<usize, Self::Error> {
let content = self.content()?;
Ok(content.len())
}
}
#[cfg(test)]
pub(crate) mod impl_tests {
macro_rules! impl_test_for_note {
($name_test:ident, $fn_test:ident, $impl_note:path) => {
#[cfg_attr(feature = "tracing", tracing_test::traced_test)]
#[test]
fn $name_test() {
$fn_test::<$impl_note>().unwrap();
}
};
}
pub(crate) use impl_test_for_note;
}