pub trait NotePath {
// Required methods
fn disassemble(&self) -> (&str, &str, &str, Option<usize>, &str);
fn exclude_copy_counter_eq(&self, p2: &Path) -> bool;
fn has_tpnote_ext(&self) -> bool;
fn has_wellformed_filename(&self) -> bool;
fn find_last_created_file(&self) -> Option<String>;
fn has_file_with_sort_tag(&self, sort_tag: &str) -> Option<String>;
fn find_file_with_sort_tag(&self, sort_tag: &str) -> Option<PathBuf>;
}
Expand description
Extents Path
with methods dealing with paths to Tp-Note files.
Required Methods§
Sourcefn disassemble(&self) -> (&str, &str, &str, Option<usize>, &str)
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 separators and copy-counter separators/brackets are removed.
Sourcefn exclude_copy_counter_eq(&self, p2: &Path) -> bool
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.
Sourcefn has_tpnote_ext(&self) -> bool
fn has_tpnote_ext(&self) -> bool
Compare to all file extensions Tp-Note can open.
Sourcefn has_wellformed_filename(&self) -> bool
fn has_wellformed_filename(&self) -> bool
Check if a Path
points to a file with a “well-formed” filename.
Sourcefn find_last_created_file(&self) -> Option<String>
fn find_last_created_file(&self) -> Option<String>
Get the filename of the last created Tp-Note file in the directory
self
. If more files have the same creation date, choose the
lexicographical last sort-tag in the current directory. Files without
sort tag are ignored.
https://doc.rust-lang.org/std/cmp/trait.Ord.html#lexicographical-comparison
Sourcefn has_file_with_sort_tag(&self, sort_tag: &str) -> Option<String>
fn has_file_with_sort_tag(&self, sort_tag: &str) -> Option<String>
Checks if the directory in self
has a Tp-Note file starting with the
sort_tag
. If found, return the filename, otherwise None
Sourcefn find_file_with_sort_tag(&self, sort_tag: &str) -> Option<PathBuf>
fn find_file_with_sort_tag(&self, sort_tag: &str) -> Option<PathBuf>
A method that searches the directory in self
for a Tp-Note
file with the sort-tag sort_tag
. It returns the filename.
Implementations on Foreign Types§
Source§impl NotePath for Path
impl NotePath for Path
Source§fn exclude_copy_counter_eq(&self, p2: &Path) -> bool
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 has_tpnote_ext(&self) -> bool
fn has_tpnote_ext(&self) -> bool
Returns True
if the path in self
ends with an extension, that Tp-
Note considers as it’s own file. To do so the extension is compared
to all items in the registered filename.extensions
table in the
configuration file.
Source§fn has_wellformed_filename(&self) -> bool
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());