From a5b549a94fcaf57c719b579830b1c460f5e03e8a Mon Sep 17 00:00:00 2001 From: bohan Date: Fri, 29 Nov 2024 11:54:33 +0800 Subject: [PATCH] docs: introduce primary param in label --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 646047c..74148d7 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ diagnostic error code: ruget::api::bad_json - [... handler options](#-handler-options) - [... dynamic diagnostics](#-dynamic-diagnostics) - [... syntax highlighting](#-syntax-highlighting) + - [... primary label](#-primary-label) - [... collection of labels](#-collection-of-labels) - [Acknowledgements](#acknowledgements) - [License](#license) @@ -689,6 +690,37 @@ trait to [`MietteHandlerOpts`] by calling the [`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting) method. See the [`highlighters`] module docs for more details. +#### ... primary label + +You can use the `primary` parameter to `label` to indicate that the label +is the primary label. + +```rust +#[derive(Debug, Diagnostic, Error)] +#[error("oops!")] +struct MyError { + #[label(primary, "main issue")] + primary_span: SourceSpan, + + #[label("other label")] + other_span: SourceSpan, +} +``` + +The `primary` parameter can be used at most once: + +```rust +#[derive(Debug, Diagnostic, Error)] +#[error("oops!")] +struct MyError { + #[label(primary, "main issue")] + primary_span: SourceSpan, + + #[label(primary, "other label")] // Error: Cannot have more than one primary label. + other_span: SourceSpan, +} +``` + #### ... collection of labels When the number of labels is unknown, you can use a collection of `SourceSpan`