use serde::{Deserialize, Deserializer}; use lexica::{Blob, StrongRef}; // see https://deer.social/profile/did:plc:63y3oh7iakdueqhlj6trojbq/post/3ltuv4skhqs2h pub fn safe_string<'de, D: Deserializer<'de>>(deserializer: D) -> Result { let str = String::deserialize(deserializer)?; Ok(str.replace('\u{0000}', "")) } pub fn blob_ref(blob: Option) -> Option { blob.map(|blob| blob.cid.to_string()) } pub fn strongref_to_parts( strongref: Option<&StrongRef>, ) -> (Option, Option) { strongref .map(|sr| (sr.uri.clone(), sr.cid.to_string())) .unzip() } pub fn empty_str_as_none(input: String) -> Option { match input.is_empty() { true => None, false => Some(input), } } pub fn u64_from_ivec(val: sled::IVec) -> Option { if val.len() == 8 { let bytes = val[0..8].try_into().ok()?; Some(u64::from_le_bytes(bytes)) } else { None } }