From f00cf28236d912de547387e1e53bbbf8a1e5a7b1 Mon Sep 17 00:00:00 2001 From: Drake Bott Date: Fri, 24 Jul 2026 19:05:17 -0500 Subject: [PATCH] fix: Make Zettel PartialOrd agree with Ord --- Cargo.lock | 343 ------------------------------------------------ Cargo.toml | 6 +- src/analysis.rs | 2 +- src/error.rs | 6 +- src/id.rs | 10 -- src/main.rs | 25 ++-- src/zettel.rs | 8 +- 7 files changed, 24 insertions(+), 376 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7bd8c90..c8e5ab1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,30 +52,12 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "anyhow" -version = "1.0.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" - -[[package]] -name = "bitflags" -version = "2.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" - [[package]] name = "camino" version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48" -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - [[package]] name = "clap" version = "4.6.1" @@ -143,34 +125,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "equivalent" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" - -[[package]] -name = "errno" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "fastrand" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" - -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "folgezettel" version = "0.3.0" @@ -180,64 +134,16 @@ dependencies = [ "csv", "heck", "serde", - "serde_json", - "tempfile", "thiserror", "walkdir", ] -[[package]] -name = "getrandom" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", - "wasip3", -] - -[[package]] -name = "hashbrown" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash", -] - -[[package]] -name = "hashbrown" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" - [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "id-arena" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - -[[package]] -name = "indexmap" -version = "2.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" -dependencies = [ - "equivalent", - "hashbrown 0.17.1", - "serde", - "serde_core", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -250,58 +156,18 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" -[[package]] -name = "leb128fmt" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" - -[[package]] -name = "libc" -version = "0.2.186" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" - -[[package]] -name = "linux-raw-sys" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" - -[[package]] -name = "log" -version = "0.4.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a" - [[package]] name = "memchr" version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" -[[package]] -name = "once_cell" -version = "1.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" - [[package]] name = "once_cell_polyfill" version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn", -] - [[package]] name = "proc-macro2" version = "1.0.106" @@ -320,25 +186,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "r-efi" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" - -[[package]] -name = "rustix" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "ryu" version = "1.0.23" @@ -354,12 +201,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "semver" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" - [[package]] name = "serde" version = "1.0.228" @@ -390,19 +231,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.150" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" -dependencies = [ - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", -] - [[package]] name = "strsim" version = "0.11.1" @@ -420,19 +248,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" -dependencies = [ - "fastrand", - "getrandom", - "once_cell", - "rustix", - "windows-sys", -] - [[package]] name = "thiserror" version = "2.0.18" @@ -459,12 +274,6 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "utf8parse" version = "0.2.2" @@ -481,58 +290,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasip2" -version = "1.0.4+wasi-0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" -dependencies = [ - "wit-bindgen 0.57.1", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen 0.51.0", -] - -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" -dependencies = [ - "leb128fmt", - "wasmparser", -] - -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags", - "hashbrown 0.15.5", - "indexmap", - "semver", -] - [[package]] name = "winapi-util" version = "0.1.11" @@ -556,103 +313,3 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ "windows-link", ] - -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen" -version = "0.57.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" - -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - -[[package]] -name = "zmij" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index e48532a..7e55fe2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "folgezettel" -version = "0.3.0" +version = "0.3.1" edition = "2024" description = "Index Folgezettel identifiers from note files" readme = "README.md" @@ -16,9 +16,5 @@ clap = { version = "4", features = ["derive"] } csv = "1" heck = "0.5.0" serde = { version = "1", features = ["derive"] } -serde_json = "1" thiserror = "2" walkdir = "2.5.0" - -[dev-dependencies] -tempfile = "3" diff --git a/src/analysis.rs b/src/analysis.rs index 236f0d0..da450c8 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -40,7 +40,7 @@ impl Analysis { }), } } - notes.sort_by(|left, right| left.id.cmp(&right.id)); + notes.sort(); diagnostics.extend(duplicate_id_diagnostics(¬es)); diagnostics.extend(missing_parent_diagnostics(¬es)); diff --git a/src/error.rs b/src/error.rs index df1a225..6b68483 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,11 +27,11 @@ pub type Result = std::result::Result; pub enum ParseIdError { #[error("id is empty")] Empty, - #[error("expected a number segment in position: {position}")] + #[error("expected a number segment at position {position}")] ExpectedNumber { position: usize }, - #[error("expected a letter segment in position: {position}")] + #[error("expected a letter segment at position {position}")] ExpectedLetter { position: usize }, - #[error("number segment at in position {position} exceeds 64 bits")] + #[error("number segment at position {position} exceeds 64 bits")] NumberOverflow { position: usize }, } diff --git a/src/id.rs b/src/id.rs index d20c69b..ac3ca99 100644 --- a/src/id.rs +++ b/src/id.rs @@ -126,10 +126,6 @@ impl FolgezettelId { Ok(Self { segments }) } - pub fn segments(&self) -> &[Segment] { - &self.segments - } - pub fn parent(&self) -> Option { let body = self.segments.split_last()?.1; let body = match body.split_last() { @@ -158,12 +154,6 @@ impl FromStr for FolgezettelId { } } -impl From<&FolgezettelId> for String { - fn from(id: &FolgezettelId) -> Self { - id.to_string() - } -} - impl Display for FolgezettelId { fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult { for segment in &self.segments { diff --git a/src/main.rs b/src/main.rs index 60ba28f..a5bf929 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,32 +14,31 @@ use csv::WriterBuilder; use serde::Serialize; use walkdir::{DirEntry, WalkDir}; -pub use analysis::Analysis; -pub use error::ParseFileNameError; -pub use id::{FolgezettelId, Segment}; -pub use zettel::Zettel; +use analysis::Analysis; +use id::FolgezettelId; +use zettel::Zettel; use crate::cli::{Cli, Relationship}; use crate::error::{CliError, DiagnosticSeverity, Result}; #[derive(Debug, Clone, PartialEq, Eq, Serialize)] -pub struct ListRecord { - pub id: String, - pub title: String, - pub file: String, +struct ListRecord { + id: String, + title: String, + file: String, } impl From<&Zettel> for ListRecord { fn from(note: &Zettel) -> Self { Self { - id: (¬e.id).into(), + id: note.id.to_string(), title: note.title.to_owned(), file: note.file.to_owned(), } } } -pub fn analyze_cwd() -> Result { +fn analyze_cwd() -> Result { Ok(Analysis::from_files(collect_files()?)) } @@ -200,7 +199,7 @@ fn write_subtree( } /// Writes records to stdout as TSV with no header row. -pub fn write_records(records: &[T]) -> Result<()> { +fn write_records(records: &[T]) -> Result<()> { let mut writer = WriterBuilder::new() .delimiter(b'\t') .has_headers(false) @@ -216,7 +215,7 @@ pub fn write_records(records: &[T]) -> Result<()> { /// Prints diagnostics to stderr — every severity when `verbose`, otherwise only /// errors — so stdout stays clean for piping. -pub fn print_diagnostics(analysis: &Analysis, verbose: bool) { +fn print_diagnostics(analysis: &Analysis, verbose: bool) { for diagnostic in analysis.diagnostics() { if verbose || diagnostic.severity() == DiagnosticSeverity::Error { eprintln!("{}: {diagnostic}", diagnostic.severity()); @@ -224,7 +223,7 @@ pub fn print_diagnostics(analysis: &Analysis, verbose: bool) { } } -pub fn exit_code(analysis: &Analysis) -> ExitCode { +fn exit_code(analysis: &Analysis) -> ExitCode { if analysis.has_errors() { ExitCode::FAILURE } else { diff --git a/src/zettel.rs b/src/zettel.rs index 5f769cb..a9f9d7b 100644 --- a/src/zettel.rs +++ b/src/zettel.rs @@ -9,7 +9,7 @@ use crate::error::ParseFileNameError; const TITLE_SEPARATORS: [char; 2] = ['-', '_']; -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Zettel { pub file: String, pub extension: OsString, @@ -57,6 +57,12 @@ impl Ord for Zettel { } } +impl PartialOrd for Zettel { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + impl Display for Zettel { fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult { write!(formatter, "{} {}", self.id, self.title) -- 2.51.2