pub trait NotePath {
    // Required methods
    fn disassemble(&self) -> (&str, &str, &str, Option<usize>, &str);
    fn exclude_copy_counter_eq(&self, p2: &Path) -> bool;
    fn filename_contains_only_sort_tag_chars(&self) -> Option<&str>;
    fn has_wellformed_filename(&self) -> bool;
    fn has_tpnote_extension(&self) -> bool;
}
Expand description

Extents Path with methods dealing with paths to Tp-Note files.

Required Methods§

source

fn disassemble(&self) -> (&str, &str, &str, Option<usize>, &str)

Helper function that decomposes a fully qualified path name into (sort_tag, stem_copy_counter_ext, stem, copy_counter, ext). All sort-tag seprators and copy-counter separators/brackets are removed.

source

fn exclude_copy_counter_eq(&self, p2: &Path) -> bool

Compares with another Path to a Tp-Note file. They are considered equal even when the copy counter is different.

source

fn filename_contains_only_sort_tag_chars(&self) -> Option<&str>

Check if the filename of Path contains only lib_cfg.filename.sort_tag_chars and return it.

source

fn has_wellformed_filename(&self) -> bool

Check if a Path points to a file with a “wellformed” filename.

source

fn has_tpnote_extension(&self) -> bool

Compare to all file extensions Tp-Note can open.

Implementations on Foreign Types§

source§

impl NotePath for Path

source§

fn exclude_copy_counter_eq(&self, p2: &Path) -> bool

Check if 2 filenames are equal. Compare all parts, except the copy counter. Consider 2 file identical even when they have a different copy counter.

source§

fn filename_contains_only_sort_tag_chars(&self) -> Option<&str>

Check if a the filename of path contains only sort tag chars. If yes, return it.

use std::path::Path;
use tpnote_lib::filename::NotePath;

let f = Path::new("20230821-");
assert_eq!(f.filename_contains_only_sort_tag_chars(), Some("20230821-"));

let f = Path::new("20230821");
assert_eq!(f.filename_contains_only_sort_tag_chars(), Some("20230821"));

let f = Path::new("2023");
assert_eq!(f.filename_contains_only_sort_tag_chars(), Some("2023"));

let f = Path::new("20230821-A");
assert_eq!(f.filename_contains_only_sort_tag_chars(), None);
source§

fn has_wellformed_filename(&self) -> bool

Check if a path points to a file with a “well formed” filename. We consider it well formed,

  • if the filename is not empty, and
    • if the filename is a dot file (len >1 and without whitespace), or
    • if the filename has an extension. A valid extension must not contain whitespace.
use std::path::Path;
use tpnote_lib::filename::NotePath;

let f = Path::new("tpnote.toml");
assert!(f.has_wellformed_filename());

let f = Path::new("dir/tpnote.toml");
assert!(f.has_wellformed_filename());

let f = Path::new("tpnote.to ml");
assert!(!f.has_wellformed_filename());
source§

fn has_tpnote_extension(&self) -> bool

True if the filename extension is considered as a Tp-Note file. Checks if the filename extension is one of the following list taken from the configuration file: FILENAME_EXTENSIONS_MD, FILENAME_EXTENSIONS_RST, FILENAME_EXTENSIONS_HTML, FILENAME_EXTENSIONS_TXT, FILENAME_EXTENSIONS_NO_VIEWER

source§

fn disassemble(&self) -> (&str, &str, &str, Option<usize>, &str)

Implementors§