find the next applicable context and return the serializer
(head: &[&'a Frame], mut current: &'a Frame)
| 109 | |
| 110 | // find the next applicable context and return the serializer |
| 111 | fn 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 | |
| 153 | impl<C: Error + Send + Sync + 'static> Serialize for Report<C> { |
| 154 | fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |