MCPcopy Create free account
hub / github.com/RetypeOS/parcode / iter

Method iter

src/reader.rs:1138–1170  ·  view source on GitHub ↗

Creates a streaming iterator over the collection. Memory usage is constant (size of one shard) regardless of total size.

(self)

Source from the content-addressed store, hash-verified

1136 /// Creates a streaming iterator over the collection.
1137 /// Memory usage is constant (size of one shard) regardless of total size.
1138 pub fn iter<T: ParcodeItem>(self) -> Result<ChunkIterator<'a, T>> {
1139 let payload = self.read_raw()?;
1140 if payload.is_empty() && self.child_count == 0 {
1141 return Ok(ChunkIterator::empty(self));
1142 }
1143 if payload.len() < 8 {
1144 return Err(ParcodeError::Format("Not a valid container".into()));
1145 }
1146
1147 let total_len = usize::try_from(u64::from_le_bytes(
1148 payload
1149 .get(0..8)
1150 .ok_or_else(|| ParcodeError::Format("Payload too short".into()))?
1151 .try_into()
1152 .map_err(|_| ParcodeError::Format("Failed to read total_len".into()))?,
1153 ))
1154 .map_err(|_| ParcodeError::Format("total_len exceeds usize range".into()))?;
1155 let runs_data = payload.get(8..).unwrap_or(&[]);
1156 let shard_runs: Vec<ShardRun> =
1157 bincode::serde::decode_from_slice(runs_data, bincode::config::standard())
1158 .map(|(obj, _)| obj)
1159 .map_err(|e| ParcodeError::Serialization(e.to_string()))?;
1160
1161 Ok(ChunkIterator {
1162 container: self,
1163 shard_runs,
1164 total_items: total_len,
1165 current_global_idx: 0,
1166 current_shard_idx: 0,
1167 current_items_in_shard: Vec::new().into_iter(),
1168 _marker: PhantomData,
1169 })
1170 }
1171
1172 // --- INTERNAL HELPERS ---
1173

Callers

nothing calls this directly

Calls 4

read_rawMethod · 0.80
is_emptyMethod · 0.45
lenMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected