2023-09-17 21:50:45 +00:00
|
|
|
#![warn(clippy::redundant_as_str)]
|
2024-02-18 14:39:34 +00:00
|
|
|
#![allow(clippy::const_is_empty)]
|
2023-09-17 21:50:45 +00:00
|
|
|
|
|
|
|
fn main() {
|
2023-09-18 20:39:09 +00:00
|
|
|
let string = "Hello, world!".to_owned();
|
2023-09-18 20:08:02 +00:00
|
|
|
|
2023-09-18 20:39:09 +00:00
|
|
|
// These methods are redundant and the `as_str` can be removed
|
2023-09-18 20:32:22 +00:00
|
|
|
let _redundant = string.as_str().as_bytes();
|
|
|
|
let _redundant = string.as_str().is_empty();
|
|
|
|
|
2023-09-18 20:37:27 +00:00
|
|
|
// These methods don't use `as_str` when they are redundant
|
2023-09-18 20:36:10 +00:00
|
|
|
let _no_as_str = string.as_bytes();
|
|
|
|
let _no_as_str = string.is_empty();
|
|
|
|
|
2024-01-03 00:21:51 +00:00
|
|
|
// These methods are not redundant, and are equivalent to
|
2023-09-18 20:39:09 +00:00
|
|
|
// doing dereferencing the string and applying the method
|
2023-09-18 20:32:22 +00:00
|
|
|
let _not_redundant = string.as_str().escape_unicode();
|
|
|
|
let _not_redundant = string.as_str().trim();
|
|
|
|
let _not_redundant = string.as_str().split_whitespace();
|
|
|
|
|
2023-09-18 20:39:09 +00:00
|
|
|
// These methods don't use `as_str` and are applied on a `str` directly
|
|
|
|
let borrowed_str = "Hello, world!";
|
2023-09-18 20:36:10 +00:00
|
|
|
let _is_str = borrowed_str.as_bytes();
|
|
|
|
let _is_str = borrowed_str.is_empty();
|
2023-09-17 21:50:45 +00:00
|
|
|
}
|