clippy: fix all warnings across all binaries

- &PathBuf → &Path in memory-search.rs signatures
- Redundant field name in graph.rs struct init
- Add truncate(false) to lock file open
- Derive Default for Store instead of manual impl
- slice::from_ref instead of &[x.clone()]
- rsplit_once instead of split().last()
- str::repeat instead of iter::repeat().take().collect()
- is_none_or instead of map_or(true, ...)
- strip_prefix instead of manual slicing

Zero warnings on `cargo clippy`.
This commit is contained in:
ProofOfConcept 2026-02-28 23:47:11 -05:00
parent 7ee6f9c651
commit 29d5ed47a1
5 changed files with 15 additions and 27 deletions

View file

@ -10,7 +10,7 @@
use std::collections::HashSet;
use std::fs;
use std::io::{self, Read, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
fn main() {
@ -138,7 +138,7 @@ fn extract_key_from_line(line: &str) -> Option<String> {
}
}
fn load_or_create_cookie(dir: &PathBuf, session_id: &str) -> String {
fn load_or_create_cookie(dir: &Path, session_id: &str) -> String {
let path = dir.join(format!("cookie-{}", session_id));
if path.exists() {
fs::read_to_string(&path).unwrap_or_default().trim().to_string()
@ -165,7 +165,7 @@ fn generate_cookie() -> String {
.collect()
}
fn load_seen(dir: &PathBuf, session_id: &str) -> HashSet<String> {
fn load_seen(dir: &Path, session_id: &str) -> HashSet<String> {
let path = dir.join(format!("seen-{}", session_id));
if path.exists() {
fs::read_to_string(path)
@ -178,7 +178,7 @@ fn load_seen(dir: &PathBuf, session_id: &str) -> HashSet<String> {
}
}
fn mark_seen(dir: &PathBuf, session_id: &str, key: &str) {
fn mark_seen(dir: &Path, session_id: &str, key: &str) {
let path = dir.join(format!("seen-{}", session_id));
if let Ok(mut f) = fs::OpenOptions::new().create(true).append(true).open(path) {
writeln!(f, "{}", key).ok();

View file

@ -49,7 +49,7 @@ impl StoreLock {
fn acquire() -> Result<Self, String> {
let path = lock_path();
let file = fs::OpenOptions::new()
.create(true).write(true).open(&path)
.create(true).truncate(false).write(true).open(&path)
.map_err(|e| format!("open lock {}: {}", path.display(), e))?;
// Blocking exclusive lock
@ -268,7 +268,7 @@ pub struct GapRecord {
}
// The full in-memory store
#[derive(Serialize, Deserialize)]
#[derive(Default, Serialize, Deserialize)]
pub struct Store {
pub nodes: HashMap<String, Node>, // key → latest node
#[serde(skip)]
@ -279,18 +279,6 @@ pub struct Store {
pub params: Params,
}
impl Default for Store {
fn default() -> Self {
Store {
nodes: HashMap::new(),
uuid_to_key: HashMap::new(),
relations: Vec::new(),
retrieval_log: Vec::new(),
gaps: Vec::new(),
params: Params::default(),
}
}
}
impl Store {
/// Load store: try state.json cache first, rebuild from capnp logs if stale
@ -498,7 +486,7 @@ impl Store {
/// Add a relation (appends to log + updates cache)
pub fn add_relation(&mut self, rel: Relation) -> Result<(), String> {
self.append_relations(&[rel.clone()])?;
self.append_relations(std::slice::from_ref(&rel))?;
self.relations.push(rel);
Ok(())
}
@ -1036,7 +1024,7 @@ impl Store {
let mut output = String::new();
for node in &sections {
if node.key.contains('#') {
let section_id = node.key.split('#').last().unwrap_or("");
let section_id = node.key.rsplit_once('#').map_or("", |(_, s)| s);
let links: Vec<_> = self.relations.iter()
.filter(|r| r.source_key == node.key && !r.deleted

View file

@ -371,7 +371,7 @@ impl Graph {
same_community,
delta_cc_source: cc_after_source - cc_before_source,
delta_cc_target: cc_after_target - cc_before_target,
delta_gini: delta_gini,
delta_gini,
assessment,
}
}

View file

@ -44,7 +44,7 @@ fn find_current_transcript() -> Option<String> {
if p.extension().map(|x| x == "jsonl").unwrap_or(false) {
if let Ok(meta) = p.metadata() {
if let Ok(mtime) = meta.modified() {
if newest.as_ref().map_or(true, |(t, _)| mtime > *t) {
if newest.as_ref().is_none_or(|(t, _)| mtime > *t) {
newest = Some((mtime, p));
}
}
@ -554,8 +554,8 @@ fn cmd_apply_agent(args: &[String]) -> Result<(), String> {
let reason = link.get("reason").and_then(|v| v.as_str()).unwrap_or("");
// Skip NOTE: targets (new topics, not existing nodes)
if target.starts_with("NOTE:") {
println!(" NOTE: {}{}", &target[5..], reason);
if let Some(note) = target.strip_prefix("NOTE:") {
println!(" NOTE: {}{}", note, reason);
continue;
}
@ -932,12 +932,12 @@ fn cmd_write(args: &[String]) -> Result<(), String> {
let mut node = existing.clone();
node.content = content;
node.version += 1;
store.append_nodes(&[node.clone()])?;
store.append_nodes(std::slice::from_ref(&node))?;
store.nodes.insert(key.clone(), node);
println!("Updated '{}' (v{})", key, store.nodes[&key].version);
} else {
let node = capnp_store::Store::new_node(&key, &content);
store.append_nodes(&[node.clone()])?;
store.append_nodes(std::slice::from_ref(&node))?;
store.uuid_to_key.insert(node.uuid, node.key.clone());
store.nodes.insert(key.clone(), node);
println!("Created '{}'", key);

View file

@ -275,7 +275,7 @@ fn format_health_section(store: &Store, graph: &Graph) -> String {
for (i, &count) in buckets.iter().enumerate() {
let lo = i as f32 / 10.0;
let hi = (i + 1) as f32 / 10.0;
let bar: String = std::iter::repeat('█').take((count as usize) / 10).collect();
let bar = "".repeat((count as usize) / 10);
out.push_str(&format!(" {:.1}-{:.1}: {:4} {}\n", lo, hi, count, bar));
}