Fast and robust atproto CAR file processing in rust
14
fork

Configure Feed

Select the types of activity you want to include in your feed.

WalkItem::is_missing and some cleanups

phil 8e64333a 03678b2f

+15 -6
+4 -5
src/mem.rs
··· 156 156 MaybeProcessedBlock::Processed(_) => Err(WalkError::BadCommitFingerprint)?, 157 157 MaybeProcessedBlock::Raw(bytes) => (serde_ipld_dagcbor::from_slice(bytes)?, bytes.clone()), 158 158 }; 159 - let root_cid: Cid = commit.data.clone().into(); 159 + let root_cid: Cid = commit.data.into(); 160 160 161 161 Ok(MemCar { 162 162 commit, ··· 194 194 /// Returns all `WalkItem` variants as-is, including `MissingRecord` and 195 195 /// `MissingSubtree` for sparse trees and CAR slices. Returns `Ok(None)` 196 196 /// when the walk is complete. 197 - /// 198 - /// TODO: make this an implementation of Iterator 197 + #[allow(clippy::should_implement_trait)] 199 198 pub fn next(&mut self) -> Result<Option<WalkItem>, WalkError> { 200 199 self.walker.step(&self.blocks, self.process) 201 200 } ··· 424 423 (serde_ipld_dagcbor::from_slice(bytes)?, bytes.clone()) 425 424 } 426 425 }; 427 - let root_cid: Cid = commit.data.clone().into(); 426 + let root_cid: Cid = commit.data.into(); 428 427 429 428 Ok(MemCar { 430 429 commit, ··· 509 508 .map_err(|e| DriveError::StorageError(DiskError::DbError(e)))? 510 509 .ok_or(DriveError::MissingCommit)?; 511 510 512 - let root_cid: Cid = commit.data.clone().into(); 511 + let root_cid: Cid = commit.data.into(); 513 512 let (node, root_bytes) = match MaybeProcessedBlock::from_bytes(db_bytes.to_vec()) { 514 513 MaybeProcessedBlock::Processed(_) => Err(WalkError::BadCommitFingerprint)?, 515 514 MaybeProcessedBlock::Raw(bytes) => (serde_ipld_dagcbor::from_slice(&bytes)?, bytes),
+1
src/slice.rs
··· 138 138 /// 139 139 /// Errors on any missing block within the range, on an MST node absent 140 140 /// within the range, or on a proof violation. 141 + #[allow(clippy::should_implement_trait)] 141 142 pub fn next(&mut self) -> Result<Option<Output>, SliceError> { 142 143 if self.done { 143 144 return Ok(None);
+10 -1
src/walk.rs
··· 112 112 MissingSubtree { cid: Cid }, 113 113 } 114 114 115 + impl WalkItem { 116 + pub fn is_missing(&self) -> bool { 117 + matches!( 118 + self, 119 + Self::MissingRecord { .. } | Self::MissingSubtree { .. } 120 + ) 121 + } 122 + } 123 + 115 124 /// A single record emitted by the walker. 116 125 #[derive(Debug, PartialEq)] 117 126 pub struct Output<T = Bytes> { ··· 279 288 280 289 // Capture what we need to emit a Node item after mpb_step consumes `thing`. 281 290 let child_link = if matches!(thing.kind, ThingKind::ChildNode) { 282 - Some(thing.link.clone()) 291 + Some(thing.link) 283 292 } else { 284 293 None 285 294 };