Skip to content

fix: Rename Label::ERROR.text().title() with Label::ERROR.with_name().title() #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub static C: u32 = 0 - 1;
"#;
let message = &[Group::with_title(
Level::ERROR
.text(Some("error: internal compiler error"))
.with_name(Some("error: internal compiler error"))
.title("could not evaluate static initializer")
.id("E0080"),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
),
Group::with_title(
Level::HELP
.text(Some("suggestion"))
.with_name(Some("suggestion"))
.title("use `break` on its own without a value inside this `while` loop"),
)
.element(
Expand Down
6 changes: 4 additions & 2 deletions src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ impl<'a> Level<'a> {
pub const NOTE: Level<'a> = NOTE;
pub const HELP: Level<'a> = HELP;

/// Replace the name describing this [`Level`]
///
/// <div class="warning">
///
/// Text passed to this function is considered "untrusted input", as such
/// all text is passed through a normalization function. Pre-styled text is
/// not allowed to be passed to this function.
///
/// </div>
pub fn text(self, text: impl Into<OptionCow<'a>>) -> Level<'a> {
pub fn with_name(self, name: impl Into<OptionCow<'a>>) -> Level<'a> {
Level {
name: Some(text.into().0),
name: Some(name.into().0),
level: self.level,
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ fn secondary_title_no_level_text() {
)
.element(
Level::NOTE
.text(None::<&str>)
.with_name(None::<&str>)
.title("expected reference `&str`\nfound reference `&'static [u8; 0]`"),
),
];
Expand Down Expand Up @@ -2442,7 +2442,7 @@ fn secondary_title_custom_level_text() {
)
.element(
Level::NOTE
.text(Some("custom"))
.with_name(Some("custom"))
.title("expected reference `&str`\nfound reference `&'static [u8; 0]`"),
),
];
Expand Down Expand Up @@ -2515,7 +2515,7 @@ fn main() {
),
Group::with_title(
Level::HELP
.text(Some("suggestion"))
.with_name(Some("suggestion"))
.title("use `break` on its own without a value inside this `while` loop")
.id("S0123"),
)
Expand Down