pub struct OwnedDiagnostic { /* private fields */ }Expand description
An owned, transport-safe diagnostic occurrence.
Implementations§
Source§impl OwnedDiagnostic
impl OwnedDiagnostic
Sourcepub fn new<T>(diagnostic: T) -> Self
pub fn new<T>(diagnostic: T) -> Self
Owns a transport-safe diagnostic.
Borrowed or local diagnostics remain usable through direct synchronous
Diagnostic::message and Diagnostic::visit, but they cannot cross
this owned boundary.
extern crate alloc;
use runic_diagnostics::{Diagnostic, OwnedDiagnostic};
use core::fmt;
#[derive(Debug)]
struct Borrowed<'a>(&'a str);
impl Diagnostic for Borrowed<'_> {
fn message(&self, out: &mut dyn fmt::Write) -> fmt::Result {
out.write_str(self.0)
}
}
let text = alloc::string::String::from("local");
let _ = OwnedDiagnostic::new(Borrowed(&text));extern crate alloc;
use alloc::rc::Rc;
use core::{cell::Cell, fmt};
use runic_diagnostics::{Diagnostic, OwnedDiagnostic};
#[derive(Debug)]
struct Local(Rc<Cell<u32>>);
impl Diagnostic for Local {
fn message(&self, out: &mut dyn fmt::Write) -> fmt::Result {
write!(out, "{}", self.0.get())
}
}
let _ = OwnedDiagnostic::new(Local(Rc::new(Cell::new(1))));pub fn as_diagnostic(&self) -> &dyn Diagnostic
pub fn descriptor(&self) -> Option<&'static DiagnosticDescriptor>
pub fn code(&self) -> Option<DiagnosticCodeRef<'_>>
pub fn severity(&self) -> Severity
pub const fn severity_override(&self) -> Option<Severity>
pub fn set_severity_override(&mut self, severity: Option<Severity>)
pub fn with_severity_override(self, severity: Severity) -> Self
pub fn metadata(&self) -> DiagnosticMetadata<'_>
pub fn contexts(&self) -> &[ContextFrame]
pub fn push_context(&mut self, context: impl Into<String>)
pub fn with_context(self, context: impl Into<String>) -> Self
pub fn attach_sources<P>(self, sources: P) -> Self
Sourcepub fn attach_session_sources<P>(self, sources: P) -> Self
pub fn attach_session_sources<P>(self, sources: P) -> Self
Retains a session source provider with this diagnostic occurrence.
This is useful when the operation that allocated session source IDs transfers diagnostics
to a caller without otherwise retaining the operation’s source manager. An explicit source
provider passed to Self::prepare or Self::display_with_sources takes precedence.
pub fn set_session_sources<P>(&mut self, sources: P)
pub fn session_sources( &self, ) -> Option<&(dyn SourceProvider + Send + Sync + 'static)>
pub fn attached_sources( &self, ) -> Option<&(dyn SourceProvider + Send + Sync + 'static)>
Sourcepub fn prepare<'a>(
&'a self,
session_sources: &'a dyn SourceProvider,
) -> Result<PreparedDiagnostic<'a>, PrepareError>
pub fn prepare<'a>( &'a self, session_sources: &'a dyn SourceProvider, ) -> Result<PreparedDiagnostic<'a>, PrepareError>
Prepares this diagnostic with its occurrence metadata and source universes.
session_sources resolves crate::SourceKey::Session spans. Sources
attached to this diagnostic continue to resolve
crate::SourceKey::Attached spans without fallback between the two
namespaces.
Sourcepub fn prepare_with_limits<'a>(
&'a self,
session_sources: &'a dyn SourceProvider,
limits: PreparationLimits,
) -> Result<PreparedDiagnostic<'a>, PrepareError>
pub fn prepare_with_limits<'a>( &'a self, session_sources: &'a dyn SourceProvider, limits: PreparationLimits, ) -> Result<PreparedDiagnostic<'a>, PrepareError>
Prepares this diagnostic with explicit resource limits.
Sourcepub fn prepare_attached(&self) -> Result<PreparedDiagnostic<'_>, PrepareError>
pub fn prepare_attached(&self) -> Result<PreparedDiagnostic<'_>, PrepareError>
Prepares this diagnostic using only sources attached to it.
Rendering a session span in the returned diagnostic will produce a missing-source error.
Sourcepub fn prepare_attached_with_limits(
&self,
limits: PreparationLimits,
) -> Result<PreparedDiagnostic<'_>, PrepareError>
pub fn prepare_attached_with_limits( &self, limits: PreparationLimits, ) -> Result<PreparedDiagnostic<'_>, PrepareError>
Prepares this diagnostic using only attached sources and explicit limits.
Sourcepub fn display(&self) -> DiagnosticDisplay<'_>
pub fn display(&self) -> DiagnosticDisplay<'_>
Returns a rich-formatting adapter using attached sources and portable defaults.
Sourcepub fn display_with_sources<'a>(
&'a self,
session_sources: &'a dyn SourceProvider,
) -> DiagnosticDisplay<'a>
pub fn display_with_sources<'a>( &'a self, session_sources: &'a dyn SourceProvider, ) -> DiagnosticDisplay<'a>
Returns a rich-formatting adapter with an explicit session source provider.
Sources attached to this diagnostic are layered with session_sources
and remain scoped to attached spans.
pub fn is<T: 'static>(&self) -> bool
pub fn downcast_ref<T: 'static>(&self) -> Option<&T>
pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>
pub fn downcast<T: 'static>(self) -> Result<Box<T>, Self>
Trait Implementations§
Source§impl Debug for OwnedDiagnostic
impl Debug for OwnedDiagnostic
Source§impl Diagnostic for OwnedDiagnostic
Delegates the semantic diagnostic protocol to the owned occurrence.
impl Diagnostic for OwnedDiagnostic
Delegates the semantic diagnostic protocol to the owned occurrence.
Occurrence transport metadata such as context frames and attached source providers is consumed
by OwnedDiagnostic::prepare; it is intentionally not exposed when an owned diagnostic is
nested as a plain Diagnostic.
Source§fn descriptor(&self) -> Option<&'static DiagnosticDescriptor>
fn descriptor(&self) -> Option<&'static DiagnosticDescriptor>
Source§fn code(&self) -> Option<DiagnosticCodeRef<'_>>
fn code(&self) -> Option<DiagnosticCodeRef<'_>>
Source§fn visit(&self, visitor: &mut dyn VisitDiagnostic)
fn visit(&self, visitor: &mut dyn VisitDiagnostic)
Source§fn cause(&self) -> Option<&(dyn Error + 'static)>
fn cause(&self) -> Option<&(dyn Error + 'static)>
core::error::Error type, if this diagnostic has oneSource§fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
Diagnostic type, if this diagnostic is derived from another