MCPcopy Create free account
hub / github.com/hashintel/hash / partition

Function partition

libs/error-stack/src/fmt/mod.rs:763–778  ·  view source on GitHub ↗

Partition the tree, this looks for the first context frame, then moves it up the chain and adds it to our results. Once we reach the end all remaining items on the stack are added to the prefix pile, which will be used in next iteration.

(stack: &'a [&'a Frame])

Source from the content-addressed store, hash-verified

761/// Once we reach the end all remaining items on the stack are added to the prefix pile,
762/// which will be used in next iteration.
763fn partition<'a>(stack: &'a [&'a Frame]) -> (Vec<(&'a Frame, Vec<&'a Frame>)>, Vec<&'a Frame>) {
764 let mut result = vec![];
765 let mut queue = vec![];
766
767 for frame in stack {
768 if matches!(frame.kind(), FrameKind::Context(_)) {
769 let frames = mem::take(&mut queue);
770
771 result.push((*frame, frames));
772 } else {
773 queue.push(*frame);
774 }
775 }
776
777 (result, queue)
778}
779
780fn debug_context(context: &(dyn Error + Send + Sync + 'static), mode: ColorMode) -> Lines {
781 context

Callers 1

debug_frameFunction · 0.85

Calls 2

takeFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected