fix: resolve ownership and borrowing errors and add serde traits

Co-authored-by: aider (openai/andrew/openrouter/google/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-25 13:06:54 -03:00
parent 53c63360cb
commit ee0545b739
7 changed files with 19 additions and 15 deletions

View File

@@ -29,6 +29,9 @@ pub enum CoreError {
impl From<rusqlite_migration::Error> for CoreError { impl From<rusqlite_migration::Error> for CoreError {
fn from(err: rusqlite_migration::Error) -> Self { fn from(err: rusqlite_migration::Error) -> Self {
CoreError::Database(rusqlite::Error::from(err)) match err {
rusqlite_migration::Error::Rusqlite(e) => CoreError::Database(e),
e => CoreError::Other(e.into()),
}
} }
} }

View File

@@ -8,7 +8,6 @@ use crate::db::{self, Meta};
use crate::compression_engine::{get_compression_engine, CompressionType}; use crate::compression_engine::{get_compression_engine, CompressionType};
use crate::modes::common::settings_compression_type; use crate::modes::common::settings_compression_type;
use clap::Command; use clap::Command;
use log::debug;
use rusqlite::Connection; use rusqlite::Connection;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs; use std::fs;

View File

@@ -1,6 +1,7 @@
use anyhow::{Context, Error, Result}; use anyhow::{Context, Error, Result};
use chrono::prelude::*; use chrono::prelude::*;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use log::*; use log::*;
use rusqlite::{Connection, OpenFlags, params}; use rusqlite::{Connection, OpenFlags, params};
use rusqlite_migration::{M, Migrations}; use rusqlite_migration::{M, Migrations};
@@ -37,7 +38,7 @@ lazy_static! {
]); ]);
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Item { pub struct Item {
pub id: Option<i64>, pub id: Option<i64>,
pub ts: DateTime<Utc>, pub ts: DateTime<Utc>,
@@ -45,13 +46,13 @@ pub struct Item {
pub compression: String, pub compression: String,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tag { pub struct Tag {
pub id: i64, pub id: i64,
pub name: String, pub name: String,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Meta { pub struct Meta {
pub id: i64, pub id: i64,
pub name: String, pub name: String,

View File

@@ -74,7 +74,7 @@ fn show_item(
let item = item_with_meta.item; let item = item_with_meta.item;
let item_id = item.id.unwrap(); let item_id = item.id.unwrap();
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect(); let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let mut table = Table::new(); let mut table = Table::new();
if std::io::stdout().is_terminal() { if std::io::stdout().is_terminal() {
@@ -156,7 +156,7 @@ fn show_item_structured(
) -> Result<()> { ) -> Result<()> {
let item = item_with_meta.item; let item = item_with_meta.item;
let item_id = item.id.unwrap(); let item_id = item.id.unwrap();
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect(); let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let mut item_path_buf = data_path.clone(); let mut item_path_buf = data_path.clone();
item_path_buf.push(item_id.to_string()); item_path_buf.push(item_id.to_string());

View File

@@ -71,7 +71,7 @@ pub fn mode_list(
for item_with_meta in items_with_meta { for item_with_meta in items_with_meta {
let item = item_with_meta.item; let item = item_with_meta.item;
let tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect(); let tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let meta = item_with_meta.meta_as_map(); let meta = item_with_meta.meta_as_map();
let mut item_path = data_path.clone(); let mut item_path = data_path.clone();
@@ -297,7 +297,7 @@ fn show_list_structured(
for item_with_meta in items_with_meta { for item_with_meta in items_with_meta {
let item = item_with_meta.item; let item = item_with_meta.item;
let item_id = item.id.unwrap(); let item_id = item.id.unwrap();
let tags = item_with_meta.tags.into_iter().map(|t| t.name).collect(); let tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let meta = item_with_meta.meta_as_map(); let meta = item_with_meta.meta_as_map();
let mut item_path = data_path.clone(); let mut item_path = data_path.clone();

View File

@@ -57,7 +57,7 @@ pub async fn handle_list_items(
// Apply ordering (default is newest first) // Apply ordering (default is newest first)
match params.order.as_deref().unwrap_or("newest") { match params.order.as_deref().unwrap_or("newest") {
"newest" => items_with_meta.sort_by(|a, b| b.item.ts.cmp(&a.item.ts)), "newest" => items_with_meta.sort_by(|a, b| b.item.ts.cmp(&a.item.ts)),
"oldest" => items_with_meta.sort_by(|a, b| a.item.ts.cmp(&a.item.ts)), "oldest" => items_with_meta.sort_by(|a, b| a.item.ts.cmp(&b.item.ts)),
_ => items_with_meta.sort_by(|a, b| b.item.ts.cmp(&a.item.ts)), // default to newest _ => items_with_meta.sort_by(|a, b| b.item.ts.cmp(&a.item.ts)), // default to newest
} }
@@ -70,7 +70,7 @@ pub async fn handle_list_items(
.into_iter() .into_iter()
.map(|item_with_meta| { .map(|item_with_meta| {
let item_id = item_with_meta.item.id.unwrap_or(0); let item_id = item_with_meta.item.id.unwrap_or(0);
let item_tags = item_with_meta.tags.into_iter().map(|t| t.name).collect(); let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let item_meta = item_with_meta.meta_as_map(); let item_meta = item_with_meta.meta_as_map();
ItemInfo { ItemInfo {

View File

@@ -100,7 +100,7 @@ impl KeepTools {
let item = item_with_content.item_with_meta.item; let item = item_with_content.item_with_meta.item;
let content = String::from_utf8_lossy(&item_with_content.content).to_string(); let content = String::from_utf8_lossy(&item_with_content.content).to_string();
let tags: Vec<String> = item_with_content.item_with_meta.tags.into_iter().map(|t| t.name).collect(); let tags: Vec<String> = item_with_content.item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let metadata = item_with_content.item_with_meta.meta_as_map(); let metadata = item_with_content.item_with_meta.meta_as_map();
let response = serde_json::json!({ let response = serde_json::json!({
@@ -118,6 +118,7 @@ impl KeepTools {
pub async fn get_latest_item(&self, args: Option<Value>) -> Result<String, ToolError> { pub async fn get_latest_item(&self, args: Option<Value>) -> Result<String, ToolError> {
let tags: Vec<String> = args let tags: Vec<String> = args
.as_ref()
.and_then(|v| v.get("tags")) .and_then(|v| v.get("tags"))
.and_then(|v| v.as_array()) .and_then(|v| v.as_array())
.map(|arr| arr.iter().filter_map(|v| v.as_str().map(|s| s.to_string())).collect()) .map(|arr| arr.iter().filter_map(|v| v.as_str().map(|s| s.to_string())).collect())
@@ -136,7 +137,7 @@ impl KeepTools {
let item = item_with_content.item_with_meta.item; let item = item_with_content.item_with_meta.item;
let content = String::from_utf8_lossy(&item_with_content.content).to_string(); let content = String::from_utf8_lossy(&item_with_content.content).to_string();
let tags: Vec<String> = item_with_content.item_with_meta.tags.into_iter().map(|t| t.name).collect(); let tags: Vec<String> = item_with_content.item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let metadata = item_with_content.item_with_meta.meta_as_map(); let metadata = item_with_content.item_with_meta.meta_as_map();
let response = serde_json::json!({ let response = serde_json::json!({
@@ -182,7 +183,7 @@ impl KeepTools {
.map(|item_with_meta| { .map(|item_with_meta| {
let item = item_with_meta.item; let item = item_with_meta.item;
let item_id = item.id.unwrap_or(0); let item_id = item.id.unwrap_or(0);
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect(); let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let item_meta = item_with_meta.meta_as_map(); let item_meta = item_with_meta.meta_as_map();
serde_json::json!({ serde_json::json!({
@@ -234,7 +235,7 @@ impl KeepTools {
.map(|item_with_meta| { .map(|item_with_meta| {
let item = item_with_meta.item; let item = item_with_meta.item;
let item_id = item.id.unwrap_or(0); let item_id = item.id.unwrap_or(0);
let item_tags: Vec<String> = item_with_meta.tags.into_iter().map(|t| t.name).collect(); let item_tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();
let item_meta = item_with_meta.meta_as_map(); let item_meta = item_with_meta.meta_as_map();
serde_json::json!({ serde_json::json!({