Skip to main content

CollectingSink

Struct CollectingSink 

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

Collects every diagnostic and remembers whether any was an error.

Used by tests and by library callers that want the full list. Always returns Ok(()) from emit.

§Examples

use mos_core::{CollectingSink, Diagnostic, DiagnosticSink, Severity, codes};

let mut sink = CollectingSink::new();
assert!(
    sink.emit(Diagnostic::simple(&codes::MOS0028, None, "unterminated"))
        .is_ok(),
    "collecting sink must not abort"
);
assert!(
    sink.emit(Diagnostic::simple(&codes::MOS0010, None, "missing ident"))
        .is_ok(),
    "collecting sink must not abort"
);

assert!(sink.had_error()); // MOS0010 is an error
assert_eq!(sink.into_diagnostics().len(), 2);

Implementations§

Source§

impl CollectingSink

Source

pub fn new() -> Self

A fresh, empty sink.

Source

pub fn had_error(&self) -> bool

Whether any Error-severity diagnostic has been emitted so far.

Source

pub fn diagnostics(&self) -> &[Diagnostic]

Borrow the collected diagnostics in emission order.

Source

pub fn into_diagnostics(self) -> Vec<Diagnostic>

Consume the sink, yielding the collected diagnostics.

Trait Implementations§

Source§

impl Debug for CollectingSink

Source§

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

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

impl Default for CollectingSink

Source§

fn default() -> CollectingSink

Returns the “default value” for a type. Read more
Source§

impl DiagnosticSink for CollectingSink

Source§

fn emit(&mut self, diagnostic: Diagnostic) -> DiagnosticResult<()>

Accept one fully-built diagnostic. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.