Rollup merge of #139031 - DaniPopes:str-trim-closure, r=tgross35

Use char::is_whitespace directly in str::trim*

Use the method directly instead of wrapping it in a closure.
This commit is contained in:
Matthias Krüger
2025-04-27 11:54:57 +02:00
committed by GitHub

View File

@@ -2115,7 +2115,7 @@ impl str {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "str_trim"]
pub fn trim(&self) -> &str {
self.trim_matches(|c: char| c.is_whitespace())
self.trim_matches(char::is_whitespace)
}
/// Returns a string slice with leading whitespace removed.
@@ -2154,7 +2154,7 @@ impl str {
#[stable(feature = "trim_direction", since = "1.30.0")]
#[rustc_diagnostic_item = "str_trim_start"]
pub fn trim_start(&self) -> &str {
self.trim_start_matches(|c: char| c.is_whitespace())
self.trim_start_matches(char::is_whitespace)
}
/// Returns a string slice with trailing whitespace removed.
@@ -2193,7 +2193,7 @@ impl str {
#[stable(feature = "trim_direction", since = "1.30.0")]
#[rustc_diagnostic_item = "str_trim_end"]
pub fn trim_end(&self) -> &str {
self.trim_end_matches(|c: char| c.is_whitespace())
self.trim_end_matches(char::is_whitespace)
}
/// Returns a string slice with leading whitespace removed.