chore: apply rustfmt formatting across API handlers and core types

Reformats import blocks, function signatures, and expression line wrapping
in stemedb-api handlers, stemedb-core serde/source_record, and serde_helpers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jordan 2026-02-21 16:43:45 -07:00
parent 02ecac9a07
commit cde30b9213
8 changed files with 34 additions and 47 deletions

View File

@ -8,7 +8,9 @@ use crate::{
error::Result,
state::AppState,
};
use stemedb_storage::{GenericIndexStore, GenericTrustRankStore, IndexStore, KVStore, TrustRankStore, key_codec};
use stemedb_storage::{
key_codec, GenericIndexStore, GenericTrustRankStore, IndexStore, KVStore, TrustRankStore,
};
/// Default half-life for trust rank decay (30 days in seconds).
const DEFAULT_HALF_LIFE_SECONDS: u64 = 30 * 24 * 60 * 60;
@ -201,9 +203,7 @@ pub async fn rebuild_indexes(
continue;
}
Err(e) => {
let msg = format!(
"hex decode failed for subject={subject} hash={hash_hex}: {e}"
);
let msg = format!("hex decode failed for subject={subject} hash={hash_hex}: {e}");
warn!("{}", msg);
if first_error.is_none() {
first_error = Some(msg);
@ -229,9 +229,7 @@ pub async fn rebuild_indexes(
}
// Rebuild SRC: source index
if let Err(e) =
index_store.add_to_source_index(&assertion.source_hash, &hash_bytes).await
{
if let Err(e) = index_store.add_to_source_index(&assertion.source_hash, &hash_bytes).await {
warn!(%subject, %hash_hex, error = %e, "Failed to add to source index");
}
@ -255,12 +253,7 @@ pub async fn rebuild_indexes(
let elapsed_ms = start.elapsed().as_millis() as u64;
info!(
rebuilt_count,
skipped_count,
elapsed_ms,
"Index rebuild complete"
);
info!(rebuilt_count, skipped_count, elapsed_ms, "Index rebuild complete");
metrics::histogram!("stemedb_http_request_duration_seconds",
"method" => "POST",

View File

@ -14,7 +14,7 @@ use crate::{
};
use stemedb_core::serde::deserialize_assertion_compat;
use stemedb_storage::{KVStore, key_codec};
use stemedb_storage::{key_codec, KVStore};
use super::query::assertion_to_dto_with_warning;

View File

@ -646,8 +646,7 @@ async fn build_impact_response(
);
if let Ok(Some(data)) = store_get_with_timeout(&*state.store, &assertion_key).await
{
if let Ok(assertion) =
stemedb_core::serde::deserialize_assertion_compat(&data)
if let Ok(assertion) = stemedb_core::serde::deserialize_assertion_compat(&data)
{
for sig in &assertion.signatures {
let agent_hex = hex::encode(sig.agent_id);

View File

@ -130,7 +130,8 @@ pub async fn list_claims(
let hash_hex = hex::encode(&hash_bytes);
let assertion_key = key_codec::assertion_key(&subject, &hash_hex);
if let Some(data) = state.store.get(&assertion_key).await? {
if let Ok(assertion) = stemedb_core::serde::deserialize_assertion_compat(&data) {
if let Ok(assertion) = stemedb_core::serde::deserialize_assertion_compat(&data)
{
if let Ok(dto) = assertion_to_dto(&assertion) {
claims.push(dto);
}

View File

@ -88,10 +88,8 @@ pub async fn list_predicates(
let prefix = key_codec::subject_predicate_scan_prefix(&subject);
let entries = state.store.scan_prefix(&prefix).await?;
let predicates: Vec<String> = entries
.iter()
.filter_map(|(k, _)| key_codec::extract_sp_key(k).map(|(_, p)| p))
.collect();
let predicates: Vec<String> =
entries.iter().filter_map(|(k, _)| key_codec::extract_sp_key(k).map(|(_, p)| p)).collect();
Ok(Json(ListPredicatesResponse { subject, predicates }))
}

View File

@ -539,8 +539,8 @@ mod tests {
assert!(deserialize::<Assertion>(&bytes).is_err());
// Compat function should succeed
let recovered = deserialize_assertion_compat(&bytes)
.expect("compat deserialize should succeed");
let recovered =
deserialize_assertion_compat(&bytes).expect("compat deserialize should succeed");
assert_eq!(recovered.subject, "Semaglutide");
assert_eq!(recovered.predicate, "reduces_weight");
@ -601,8 +601,8 @@ mod tests {
assert!(deserialize::<SourceRecord>(&bytes).is_err());
// Compat function should succeed
let recovered = deserialize_source_record_compat(&bytes)
.expect("compat deserialize should succeed");
let recovered =
deserialize_source_record_compat(&bytes).expect("compat deserialize should succeed");
assert_eq!(recovered.hash, [42u8; 32]);
assert_eq!(recovered.label, "RFC 7519");
@ -613,14 +613,8 @@ mod tests {
#[test]
fn test_current_source_record_also_works_via_compat() {
let record = SourceRecord::new(
[1u8; 32],
"Test".to_string(),
None,
2,
1000,
)
.with_content(Some("Full text content".to_string()));
let record = SourceRecord::new([1u8; 32], "Test".to_string(), None, 2, 1000)
.with_content(Some("Full text content".to_string()));
let bytes = serialize(&record).expect("serialize");
let recovered = deserialize_source_record_compat(&bytes)

View File

@ -142,7 +142,17 @@ impl SourceRecord {
updated_at: u64,
notes: Option<String>,
) -> Self {
Self { hash, label, url, tier: tier.min(5), status, created_at, updated_at, notes, content: None }
Self {
hash,
label,
url,
tier: tier.min(5),
status,
created_at,
updated_at,
notes,
content: None,
}
}
/// Set the full-text content of the source document.
@ -281,14 +291,8 @@ mod tests {
#[test]
fn test_rkyv_roundtrip_with_content() {
let hash = [42u8; 32];
let record = SourceRecord::new(
hash,
"FDA Approval Letter".to_string(),
None,
0,
1000,
)
.with_content(Some("Full text of the FDA approval letter...".to_string()));
let record = SourceRecord::new(hash, "FDA Approval Letter".to_string(), None, 0, 1000)
.with_content(Some("Full text of the FDA approval letter...".to_string()));
let bytes = crate::serde::serialize(&record).expect("Failed to serialize SourceRecord");
let recovered: SourceRecord =
@ -305,8 +309,8 @@ mod tests {
.with_content(Some("content".to_string()));
assert_eq!(record.content, Some("content".to_string()));
let record_none = SourceRecord::new(hash, "Test".to_string(), None, 0, 1000)
.with_content(None);
let record_none =
SourceRecord::new(hash, "Test".to_string(), None, 0, 1000).with_content(None);
assert!(record_none.content.is_none());
}
}

View File

@ -47,9 +47,7 @@ where
/// Deserialize a SourceRecord with backward compatibility for the pre-content layout.
///
/// Maps deserialization errors to [`StorageError::Serialization`].
pub fn deserialize_source_record_compat(
data: &[u8],
) -> Result<stemedb_core::types::SourceRecord> {
pub fn deserialize_source_record_compat(data: &[u8]) -> Result<stemedb_core::types::SourceRecord> {
stemedb_core::serde::deserialize_source_record_compat(data)
.map_err(|e| StorageError::Serialization(e.to_string()))
}