feat: enhance strictness of Rust compiler settings and improve code quality by treating warnings as errors
This commit is contained in:
@@ -27,8 +27,6 @@ const MAX_MEMORY_ENTRIES: usize = 10_000;
|
||||
pub struct EditLog {
|
||||
pub entries: Vec<EditLogEntry>,
|
||||
pub path: std::path::PathBuf,
|
||||
/// Total entries on disk (may exceed `entries.len()` if truncated).
|
||||
pub total_on_disk: usize,
|
||||
}
|
||||
|
||||
impl EditLog {
|
||||
@@ -37,28 +35,26 @@ impl EditLog {
|
||||
/// `MAX_MEMORY_ENTRIES` to prevent OOM).
|
||||
pub fn new(session_dir: &std::path::Path) -> Self {
|
||||
let path = session_dir.join("edits.jsonl");
|
||||
let (entries, total_on_disk) = Self::load_from_disk(&path);
|
||||
EditLog { entries, path, total_on_disk }
|
||||
let entries = Self::load_from_disk(&path);
|
||||
EditLog { entries, path }
|
||||
}
|
||||
|
||||
/// Reads lines of edits.jsonl into memory, keeping only the most recent
|
||||
/// `MAX_MEMORY_ENTRIES` entries. The full history is preserved on disk
|
||||
/// regardless of the in-memory limit.
|
||||
fn load_from_disk(path: &std::path::Path) -> (Vec<EditLogEntry>, usize) {
|
||||
fn load_from_disk(path: &std::path::Path) -> Vec<EditLogEntry> {
|
||||
let file = match std::fs::File::open(path) {
|
||||
Ok(f) => f,
|
||||
Err(_) => return (Vec::new(), 0),
|
||||
Err(_) => return Vec::new(),
|
||||
};
|
||||
use std::io::{BufRead, BufReader};
|
||||
let reader = BufReader::new(file);
|
||||
let mut entries: Vec<EditLogEntry> = Vec::new();
|
||||
let mut total = 0usize;
|
||||
for line in reader.lines() {
|
||||
let line = match line {
|
||||
Ok(l) => l,
|
||||
Err(_) => continue,
|
||||
};
|
||||
total += 1;
|
||||
if let Ok(entry) = serde_json::from_str::<EditLogEntry>(&line) {
|
||||
// Keep only the most recent entries in memory
|
||||
if entries.len() >= MAX_MEMORY_ENTRIES {
|
||||
@@ -68,7 +64,7 @@ impl EditLog {
|
||||
entries.push(entry);
|
||||
}
|
||||
}
|
||||
(entries, total)
|
||||
entries
|
||||
}
|
||||
|
||||
/// Append one entry to `edits.jsonl` on disk and to the in-memory log,
|
||||
|
||||
Reference in New Issue
Block a user