Gets the [`Diagnostic`] associated with the error, if any. If there is more than one, only the outermost [`Diagnostic`] is returned.
(&self)
| 607 | /// Gets the [`Diagnostic`] associated with the error, if any. If there is |
| 608 | /// more than one, only the outermost [`Diagnostic`] is returned. |
| 609 | pub fn diagnostic(&self) -> Option<&Diagnostic> { |
| 610 | struct DiagnosticsIterator<'a> { |
| 611 | head: &'a DataFusionError, |
| 612 | } |
| 613 | |
| 614 | impl<'a> Iterator for DiagnosticsIterator<'a> { |
| 615 | type Item = &'a Diagnostic; |
| 616 | |
| 617 | fn next(&mut self) -> Option<Self::Item> { |
| 618 | loop { |
| 619 | if let DataFusionError::Diagnostic(diagnostics, source) = self.head { |
| 620 | self.head = source.as_ref(); |
| 621 | return Some(diagnostics); |
| 622 | } |
| 623 | |
| 624 | if let Some(source) = self |
| 625 | .head |
| 626 | .source() |
| 627 | .and_then(|source| source.downcast_ref::<DataFusionError>()) |
| 628 | { |
| 629 | self.head = source; |
| 630 | } else { |
| 631 | return None; |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | DiagnosticsIterator { head: self }.next() |
| 638 | } |
| 639 | |
| 640 | /// Return an iterator over this [`DataFusionError`] and any other |
| 641 | /// [`DataFusionError`]s in a [`DataFusionError::Collection`]. |