Skip to content

Commit a93afcf

Browse files
authored
docs: introduce primary param in label (#413)
1 parent 9ba6fad commit a93afcf

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ diagnostic error code: ruget::api::bad_json
5151
- [... handler options](#-handler-options)
5252
- [... dynamic diagnostics](#-dynamic-diagnostics)
5353
- [... syntax highlighting](#-syntax-highlighting)
54+
- [... primary label](#-primary-label)
5455
- [... collection of labels](#-collection-of-labels)
5556
- [Acknowledgements](#acknowledgements)
5657
- [License](#license)
@@ -689,6 +690,37 @@ trait to [`MietteHandlerOpts`] by calling the
689690
[`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting)
690691
method. See the [`highlighters`] module docs for more details.
691692

693+
#### ... primary label
694+
695+
You can use the `primary` parameter to `label` to indicate that the label
696+
is the primary label.
697+
698+
```rust
699+
#[derive(Debug, Diagnostic, Error)]
700+
#[error("oops!")]
701+
struct MyError {
702+
#[label(primary, "main issue")]
703+
primary_span: SourceSpan,
704+
705+
#[label("other label")]
706+
other_span: SourceSpan,
707+
}
708+
```
709+
710+
The `primary` parameter can be used at most once:
711+
712+
```rust
713+
#[derive(Debug, Diagnostic, Error)]
714+
#[error("oops!")]
715+
struct MyError {
716+
#[label(primary, "main issue")]
717+
primary_span: SourceSpan,
718+
719+
#[label(primary, "other label")] // Error: Cannot have more than one primary label.
720+
other_span: SourceSpan,
721+
}
722+
```
723+
692724
#### ... collection of labels
693725

694726
When the number of labels is unknown, you can use a collection of `SourceSpan`

0 commit comments

Comments
 (0)