pub struct Diagnostic { /* private fields */ }Expand description
One finding about the data.
A finding always has a code, and through the code always has a cause and a remedy — neither is something a call site can forget to supply. The message is optional and defaults to the code’s registered cause, so raising a finding that needs no elaboration allocates nothing.
§Examples
use molframe_core::{Code, Diagnostic, Severity};
let finding = Diagnostic::new(Code::W3203).in_category("atom_site").at_row(17);
assert_eq!(finding.severity(), Severity::Loose);
assert_eq!(finding.message(), "element inferred from the atom name");
assert!(!finding.remedy().is_empty());Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn retained_bytes(&self) -> usize
pub fn retained_bytes(&self) -> usize
Heap bytes retained by this occurrence’s owned details.
Sourcepub fn new(code: Code) -> Self
pub fn new(code: Code) -> Self
Creates a finding carrying the code’s registered severity and cause.
Sourcepub fn with_message(self, message: impl Into<Box<str>>) -> Self
pub fn with_message(self, message: impl Into<Box<str>>) -> Self
Replaces the message with one describing this occurrence.
Use it when the specifics matter; leave it alone when the registered cause already says everything there is to say.
Sourcepub const fn with_severity(self, severity: Severity) -> Self
pub const fn with_severity(self, severity: Severity) -> Self
Overrides the severity for this occurrence.
The registry decides severity in general. This exists for the cases where the same code is genuinely worse in one context than another.
Sourcepub fn in_category(self, category: impl Into<Box<str>>) -> Self
pub fn in_category(self, category: impl Into<Box<str>>) -> Self
Records the category this finding concerns.
Sourcepub fn about_field(self, field: impl Into<Box<str>>) -> Self
pub fn about_field(self, field: impl Into<Box<str>>) -> Self
Records the item this finding concerns.
Sourcepub fn with_context(
self,
label: &'static str,
value: impl Into<Box<str>>,
) -> Self
pub fn with_context( self, label: &'static str, value: impl Into<Box<str>>, ) -> Self
Attaches a labelled detail.
Sourcepub fn span(&self) -> Option<ByteSpan>
pub fn span(&self) -> Option<ByteSpan>
Where in the source this was raised, if a position was known.
Sourcepub fn context(&self) -> &[ContextItem]
pub fn context(&self) -> &[ContextItem]
The labelled details attached to this finding.
Sourcepub const fn is_error(&self, strictness: Strictness) -> bool
pub const fn is_error(&self, strictness: Strictness) -> bool
Returns true when this finding is an error at the given strictness.
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl Display for Diagnostic
impl Display for Diagnostic
impl Eq for Diagnostic
Source§impl Extend<Diagnostic> for Diagnostics
impl Extend<Diagnostic> for Diagnostics
Source§fn extend<T: IntoIterator<Item = Diagnostic>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Diagnostic>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl From<&!> for Diagnostic
impl From<&!> for Diagnostic
Source§fn from(never: &Infallible) -> Self
fn from(never: &Infallible) -> Self
An error that cannot be constructed has no code to name.
Source§impl From<&ContextError> for Diagnostic
impl From<&ContextError> for Diagnostic
Source§fn from(_error: &ContextError) -> Self
fn from(_error: &ContextError) -> Self
Source§impl From<&Diagnostic> for Diagnostic
impl From<&Diagnostic> for Diagnostic
Source§fn from(diagnostic: &Diagnostic) -> Self
fn from(diagnostic: &Diagnostic) -> Self
A finding is already a diagnostic; kernels that fail with one convert by copy.
Source§impl From<&MemoryBudgetError> for Diagnostic
impl From<&MemoryBudgetError> for Diagnostic
Source§fn from(_error: &MemoryBudgetError) -> Self
fn from(_error: &MemoryBudgetError) -> Self
Source§impl From<&PolicyParseError> for Diagnostic
impl From<&PolicyParseError> for Diagnostic
Source§fn from(_error: &PolicyParseError) -> Self
fn from(_error: &PolicyParseError) -> Self
Source§impl From<&StructureBatchError> for Diagnostic
impl From<&StructureBatchError> for Diagnostic
Source§fn from(error: &StructureBatchError) -> Self
fn from(error: &StructureBatchError) -> Self
A wrapped diagnostic is returned as it is, so its code, remedy and span survive; the rest name the kind of limit that stopped the read.
Source§impl From<ContextError> for Diagnostic
impl From<ContextError> for Diagnostic
Source§fn from(value: ContextError) -> Self
fn from(value: ContextError) -> Self
Source§impl From<Diagnostic> for Findings
impl From<Diagnostic> for Findings
Source§fn from(finding: Diagnostic) -> Self
fn from(finding: Diagnostic) -> Self
Source§impl From<Diagnostic> for StructureBatchError
impl From<Diagnostic> for StructureBatchError
Source§fn from(error: Diagnostic) -> Self
fn from(error: Diagnostic) -> Self
Source§impl From<MemoryBudgetError> for Diagnostic
impl From<MemoryBudgetError> for Diagnostic
Source§fn from(value: MemoryBudgetError) -> Self
fn from(value: MemoryBudgetError) -> Self
Source§impl From<PolicyParseError> for Diagnostic
impl From<PolicyParseError> for Diagnostic
Source§fn from(value: PolicyParseError) -> Self
fn from(value: PolicyParseError) -> Self
Source§impl From<StructureBatchError> for Diagnostic
impl From<StructureBatchError> for Diagnostic
Source§fn from(error: StructureBatchError) -> Self
fn from(error: StructureBatchError) -> Self
Source§impl PartialEq for Diagnostic
impl PartialEq for Diagnostic
impl StructuralPartialEq for Diagnostic
Auto Trait Implementations§
impl Freeze for Diagnostic
impl RefUnwindSafe for Diagnostic
impl Send for Diagnostic
impl Sync for Diagnostic
impl Unpin for Diagnostic
impl UnsafeUnpin for Diagnostic
impl UnwindSafe for Diagnostic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more