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:
parent
7ee6f9c651
commit
29d5ed47a1
5 changed files with 15 additions and 27 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
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));
|
let path = dir.join(format!("cookie-{}", session_id));
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
fs::read_to_string(&path).unwrap_or_default().trim().to_string()
|
fs::read_to_string(&path).unwrap_or_default().trim().to_string()
|
||||||
|
|
@ -165,7 +165,7 @@ fn generate_cookie() -> String {
|
||||||
.collect()
|
.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));
|
let path = dir.join(format!("seen-{}", session_id));
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
fs::read_to_string(path)
|
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));
|
let path = dir.join(format!("seen-{}", session_id));
|
||||||
if let Ok(mut f) = fs::OpenOptions::new().create(true).append(true).open(path) {
|
if let Ok(mut f) = fs::OpenOptions::new().create(true).append(true).open(path) {
|
||||||
writeln!(f, "{}", key).ok();
|
writeln!(f, "{}", key).ok();
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ impl StoreLock {
|
||||||
fn acquire() -> Result<Self, String> {
|
fn acquire() -> Result<Self, String> {
|
||||||
let path = lock_path();
|
let path = lock_path();
|
||||||
let file = fs::OpenOptions::new()
|
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))?;
|
.map_err(|e| format!("open lock {}: {}", path.display(), e))?;
|
||||||
|
|
||||||
// Blocking exclusive lock
|
// Blocking exclusive lock
|
||||||
|
|
@ -268,7 +268,7 @@ pub struct GapRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The full in-memory store
|
// The full in-memory store
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
pub nodes: HashMap<String, Node>, // key → latest node
|
pub nodes: HashMap<String, Node>, // key → latest node
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
|
|
@ -279,18 +279,6 @@ pub struct Store {
|
||||||
pub params: Params,
|
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 {
|
impl Store {
|
||||||
/// Load store: try state.json cache first, rebuild from capnp logs if stale
|
/// 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)
|
/// Add a relation (appends to log + updates cache)
|
||||||
pub fn add_relation(&mut self, rel: Relation) -> Result<(), String> {
|
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);
|
self.relations.push(rel);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -1036,7 +1024,7 @@ impl Store {
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
for node in §ions {
|
for node in §ions {
|
||||||
if node.key.contains('#') {
|
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()
|
let links: Vec<_> = self.relations.iter()
|
||||||
.filter(|r| r.source_key == node.key && !r.deleted
|
.filter(|r| r.source_key == node.key && !r.deleted
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,7 @@ impl Graph {
|
||||||
same_community,
|
same_community,
|
||||||
delta_cc_source: cc_after_source - cc_before_source,
|
delta_cc_source: cc_after_source - cc_before_source,
|
||||||
delta_cc_target: cc_after_target - cc_before_target,
|
delta_cc_target: cc_after_target - cc_before_target,
|
||||||
delta_gini: delta_gini,
|
delta_gini,
|
||||||
assessment,
|
assessment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -44,7 +44,7 @@ fn find_current_transcript() -> Option<String> {
|
||||||
if p.extension().map(|x| x == "jsonl").unwrap_or(false) {
|
if p.extension().map(|x| x == "jsonl").unwrap_or(false) {
|
||||||
if let Ok(meta) = p.metadata() {
|
if let Ok(meta) = p.metadata() {
|
||||||
if let Ok(mtime) = meta.modified() {
|
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));
|
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("");
|
let reason = link.get("reason").and_then(|v| v.as_str()).unwrap_or("");
|
||||||
|
|
||||||
// Skip NOTE: targets (new topics, not existing nodes)
|
// Skip NOTE: targets (new topics, not existing nodes)
|
||||||
if target.starts_with("NOTE:") {
|
if let Some(note) = target.strip_prefix("NOTE:") {
|
||||||
println!(" NOTE: {} — {}", &target[5..], reason);
|
println!(" NOTE: {} — {}", note, reason);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -932,12 +932,12 @@ fn cmd_write(args: &[String]) -> Result<(), String> {
|
||||||
let mut node = existing.clone();
|
let mut node = existing.clone();
|
||||||
node.content = content;
|
node.content = content;
|
||||||
node.version += 1;
|
node.version += 1;
|
||||||
store.append_nodes(&[node.clone()])?;
|
store.append_nodes(std::slice::from_ref(&node))?;
|
||||||
store.nodes.insert(key.clone(), node);
|
store.nodes.insert(key.clone(), node);
|
||||||
println!("Updated '{}' (v{})", key, store.nodes[&key].version);
|
println!("Updated '{}' (v{})", key, store.nodes[&key].version);
|
||||||
} else {
|
} else {
|
||||||
let node = capnp_store::Store::new_node(&key, &content);
|
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.uuid_to_key.insert(node.uuid, node.key.clone());
|
||||||
store.nodes.insert(key.clone(), node);
|
store.nodes.insert(key.clone(), node);
|
||||||
println!("Created '{}'", key);
|
println!("Created '{}'", key);
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ fn format_health_section(store: &Store, graph: &Graph) -> String {
|
||||||
for (i, &count) in buckets.iter().enumerate() {
|
for (i, &count) in buckets.iter().enumerate() {
|
||||||
let lo = i as f32 / 10.0;
|
let lo = i as f32 / 10.0;
|
||||||
let hi = (i + 1) 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));
|
out.push_str(&format!(" {:.1}-{:.1}: {:4} {}\n", lo, hi, count, bar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue