Skip to main content

OwnedDiagnostic

Struct OwnedDiagnostic 

Source
pub struct OwnedDiagnostic { /* private fields */ }
Expand description

An owned, transport-safe diagnostic occurrence.

Implementations§

Source§

impl OwnedDiagnostic

Source

pub fn new<T>(diagnostic: T) -> Self
where T: Diagnostic + Send + Sync + 'static,

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))));
Source

pub fn as_diagnostic(&self) -> &dyn Diagnostic

Source

pub fn descriptor(&self) -> Option<&'static DiagnosticDescriptor>

Source

pub fn code(&self) -> Option<DiagnosticCodeRef<'_>>

Source

pub fn tags(&self) -> &[DiagnosticTag]

Source

pub fn severity(&self) -> Severity

Source

pub const fn severity_override(&self) -> Option<Severity>

Source

pub fn set_severity_override(&mut self, severity: Option<Severity>)

Source

pub fn with_severity_override(self, severity: Severity) -> Self

Source

pub fn metadata(&self) -> DiagnosticMetadata<'_>

Source

pub fn contexts(&self) -> &[ContextFrame]

Source

pub fn push_context(&mut self, context: impl Into<String>)

Source

pub fn with_context(self, context: impl Into<String>) -> Self

Source

pub fn attach_sources<P>(self, sources: P) -> Self
where P: SourceProvider + Send + Sync + 'static,

Source

pub fn attach_session_sources<P>(self, sources: P) -> Self
where P: SourceProvider + Send + Sync + 'static,

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.

Source

pub fn set_session_sources<P>(&mut self, sources: P)
where P: SourceProvider + Send + Sync + 'static,

Source

pub fn session_sources( &self, ) -> Option<&(dyn SourceProvider + Send + Sync + 'static)>

Source

pub fn attached_sources( &self, ) -> Option<&(dyn SourceProvider + Send + Sync + 'static)>

Source

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.

Source

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.

Source

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.

Source

pub fn prepare_attached_with_limits( &self, limits: PreparationLimits, ) -> Result<PreparedDiagnostic<'_>, PrepareError>

Prepares this diagnostic using only attached sources and explicit limits.

Source

pub fn display(&self) -> DiagnosticDisplay<'_>

Returns a rich-formatting adapter using attached sources and portable defaults.

Source

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.

Source

pub fn is<T: 'static>(&self) -> bool

Source

pub fn downcast_ref<T: 'static>(&self) -> Option<&T>

Source

pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Source

pub fn downcast<T: 'static>(self) -> Result<Box<T>, Self>

Trait Implementations§

Source§

impl Debug for OwnedDiagnostic

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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 message(&self, out: &mut dyn Write) -> Result

Write the message for this diagnostic to out
Source§

fn descriptor(&self) -> Option<&'static DiagnosticDescriptor>

An optional descriptor for this diagnostic
Source§

fn code(&self) -> Option<DiagnosticCodeRef<'_>>

An optional diagnostic code
Source§

fn severity(&self) -> Severity

The severity of this diagnostic. Read more
Source§

fn tags(&self) -> &[DiagnosticTag]

Tags associated with this diagnostic
Source§

fn visit(&self, visitor: &mut dyn VisitDiagnostic)

Visit the structured children of this diagnostic (e.g. labels, notes, etc.)
Source§

fn cause(&self) -> Option<&(dyn Error + 'static)>

Returns the associated core::error::Error type, if this diagnostic has one
Source§

fn diagnostic_source(&self) -> Option<&dyn Diagnostic>

Returns a source Diagnostic type, if this diagnostic is derived from another
Source§

impl Display for OwnedDiagnostic

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Report> for OwnedDiagnostic

Source§

fn from(report: Report) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.