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

View File

@ -14,7 +14,7 @@ use crate::{
}; };
use stemedb_core::serde::deserialize_assertion_compat; 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; 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(Some(data)) = store_get_with_timeout(&*state.store, &assertion_key).await
{ {
if let Ok(assertion) = if let Ok(assertion) = stemedb_core::serde::deserialize_assertion_compat(&data)
stemedb_core::serde::deserialize_assertion_compat(&data)
{ {
for sig in &assertion.signatures { for sig in &assertion.signatures {
let agent_hex = hex::encode(sig.agent_id); 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 hash_hex = hex::encode(&hash_bytes);
let assertion_key = key_codec::assertion_key(&subject, &hash_hex); let assertion_key = key_codec::assertion_key(&subject, &hash_hex);
if let Some(data) = state.store.get(&assertion_key).await? { 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) { if let Ok(dto) = assertion_to_dto(&assertion) {
claims.push(dto); claims.push(dto);
} }

View File

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

View File

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

View File

@ -142,7 +142,17 @@ impl SourceRecord {
updated_at: u64, updated_at: u64,
notes: Option<String>, notes: Option<String>,
) -> Self { ) -> 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. /// Set the full-text content of the source document.
@ -281,14 +291,8 @@ mod tests {
#[test] #[test]
fn test_rkyv_roundtrip_with_content() { fn test_rkyv_roundtrip_with_content() {
let hash = [42u8; 32]; let hash = [42u8; 32];
let record = SourceRecord::new( let record = SourceRecord::new(hash, "FDA Approval Letter".to_string(), None, 0, 1000)
hash, .with_content(Some("Full text of the FDA approval letter...".to_string()));
"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 bytes = crate::serde::serialize(&record).expect("Failed to serialize SourceRecord");
let recovered: SourceRecord = let recovered: SourceRecord =
@ -305,8 +309,8 @@ mod tests {
.with_content(Some("content".to_string())); .with_content(Some("content".to_string()));
assert_eq!(record.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) let record_none =
.with_content(None); SourceRecord::new(hash, "Test".to_string(), None, 0, 1000).with_content(None);
assert!(record_none.content.is_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. /// Deserialize a SourceRecord with backward compatibility for the pre-content layout.
/// ///
/// Maps deserialization errors to [`StorageError::Serialization`]. /// Maps deserialization errors to [`StorageError::Serialization`].
pub fn deserialize_source_record_compat( pub fn deserialize_source_record_compat(data: &[u8]) -> Result<stemedb_core::types::SourceRecord> {
data: &[u8],
) -> Result<stemedb_core::types::SourceRecord> {
stemedb_core::serde::deserialize_source_record_compat(data) stemedb_core::serde::deserialize_source_record_compat(data)
.map_err(|e| StorageError::Serialization(e.to_string())) .map_err(|e| StorageError::Serialization(e.to_string()))
} }