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

Method next

src/reader.rs:1277–1315  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

1275 type Item = Result<T>;
1276
1277 fn next(&mut self) -> Option<Self::Item> {
1278 if self.current_global_idx >= self.total_items {
1279 return None;
1280 }
1281
1282 // 1. Try to pull from current loaded shard
1283 if let Some(item) = self.current_items_in_shard.next() {
1284 self.current_global_idx += 1;
1285 return Some(Ok(item));
1286 }
1287
1288 // 2. Buffer empty? Load next shard
1289 if self.current_shard_idx >= self.container.child_count as usize {
1290 return Some(Err(ParcodeError::Internal(
1291 "Iterator mismatch: runs out of shards".into(),
1292 )));
1293 }
1294
1295 // Load logic
1296 let next_shard_res = self
1297 .container
1298 .get_child_by_index(self.current_shard_idx)
1299 .and_then(|node| {
1300 let payload = node.read_raw()?;
1301 let mut cursor = std::io::Cursor::new(payload.as_ref());
1302 let children = node.children()?;
1303 let mut child_iter = children.into_iter();
1304 T::read_slice_from_shard(&mut cursor, &mut child_iter)
1305 });
1306
1307 match next_shard_res {
1308 Ok(items) => {
1309 self.current_items_in_shard = items.into_iter();
1310 self.current_shard_idx += 1;
1311 self.next()
1312 }
1313 Err(e) => Some(Err(e)),
1314 }
1315 }
1316}

Callers

nothing calls this directly

Calls 3

get_child_by_indexMethod · 0.80
read_rawMethod · 0.80
childrenMethod · 0.80

Tested by

no test coverage detected