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

Function find_next

libs/error-stack/src/serde.rs:111–151  ·  view source on GitHub ↗

find the next applicable context and return the serializer

(head: &[&'a Frame], mut current: &'a Frame)

Source from the content-addressed store, hash-verified

109
110// find the next applicable context and return the serializer
111fn find_next<'a>(head: &[&'a Frame], mut current: &'a Frame) -> Vec<SerializeContext<'a>> {
112 let mut attachments = vec![];
113 attachments.extend(head);
114
115 loop {
116 match current.kind() {
117 FrameKind::Context(context) => {
118 // found the context, return all attachments (reversed)
119 attachments.reverse();
120
121 return vec![SerializeContext {
122 attachments,
123 context,
124 sources: current.sources(),
125 }];
126 }
127 FrameKind::Attachment(_) => match current.sources() {
128 [] => {
129 // there are no more frames, therefore we need to abandon
130 // this is theoretically impossible (the bottom is always a context), but not
131 // enforced
132 return vec![];
133 }
134 [source] => {
135 attachments.push(current);
136
137 current = source;
138 }
139 sources => {
140 // there are multiple sources, we need to recursively probe each of them
141 attachments.push(current);
142
143 return sources
144 .iter()
145 .flat_map(|source| find_next(&attachments, source))
146 .collect();
147 }
148 },
149 }
150 }
151}
152
153impl<C: Error + Send + Sync + 'static> Serialize for Report<C> {
154 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>

Callers 1

serializeMethod · 0.85

Calls 7

sourcesMethod · 0.80
collectMethod · 0.80
pushMethod · 0.65
extendMethod · 0.45
kindMethod · 0.45
reverseMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected