Skip to main content

zyn_core/mark/
mod.rs

1//! Diagnostic construction utilities.
2//!
3//! The [`mark`](self) module provides free functions returning a [`DiagnosticBuilder`],
4//! which accumulates diagnostics and is finalized into an immutable [`Diagnostic`]
5//! via [`DiagnosticBuilder::build`].
6//!
7//! # Quick start
8//!
9//! ```ignore
10//! // Single error
11//! return Err(mark::error("field `name` is required").build());
12//!
13//! // Accumulator
14//! let d = mark::new()
15//!     .add(mark::error("missing `x`"))
16//!     .add(mark::help("add `x: u32` to your struct"))
17//!     .build();
18//! if d.is_error() { return d.emit(); }
19//! ```
20
21mod diagnostic;
22mod level;
23mod span;
24
25pub use diagnostic::Diagnostic;
26pub use diagnostic::DiagnosticBuilder;
27pub use diagnostic::Result;
28pub use level::*;
29pub use span::*;
30
31/// Creates an empty diagnostic builder.
32pub fn new() -> DiagnosticBuilder {
33    DiagnosticBuilder::default()
34}
35
36/// Creates an error diagnostic builder with the given message.
37pub fn error(message: impl Into<String>) -> DiagnosticBuilder {
38    DiagnosticBuilder::default()
39        .level(Level::Error)
40        .message(message)
41}
42
43/// Creates a warning diagnostic builder with the given message.
44pub fn warning(message: impl Into<String>) -> DiagnosticBuilder {
45    DiagnosticBuilder::default()
46        .level(Level::Warning)
47        .message(message)
48}
49
50/// Creates a note diagnostic builder with the given message.
51pub fn note(message: impl Into<String>) -> DiagnosticBuilder {
52    DiagnosticBuilder::default()
53        .level(Level::Note)
54        .message(message)
55}
56
57/// Creates a help diagnostic builder with the given message.
58pub fn help(message: impl Into<String>) -> DiagnosticBuilder {
59    DiagnosticBuilder::default()
60        .level(Level::Help)
61        .message(message)
62}