chore: add clippy::string_slice

Fixes: https://github.com/ratatui-org/ratatui/issues/1056
This commit is contained in:
Josh McKinney 2024-04-25 16:32:04 -07:00
parent 4bfdc15b80
commit 9692366d12
No known key found for this signature in database
GPG key ID: 722287396A903BC5
3 changed files with 15 additions and 1 deletions

View file

@ -99,6 +99,7 @@ string_slice = "warn"
string_to_string = "warn"
unnecessary_self_imports = "warn"
use_self = "warn"
string_slice = "warn"
[features]
#! The crate provides a set of optional features that can be enabled in your `cargo.toml` file.

View file

@ -313,7 +313,16 @@ impl FromStr for Color {
_ => {
if let Ok(index) = s.parse::<u8>() {
Self::Indexed(index)
} else if let Some((r, g, b)) = parse_hex_color(s) {
} else if let (Ok(r), Ok(g), Ok(b)) = {
if !s.starts_with('#') || s.len() != 7 {
return Err(ParseColorError);
}
(
u8::from_str_radix(&s.chars().skip(1).take(2).collect::<String>(), 16),
u8::from_str_radix(&s.chars().skip(3).take(2).collect::<String>(), 16),
u8::from_str_radix(&s.chars().skip(5).take(2).collect::<String>(), 16),
)
} {
Self::Rgb(r, g, b)
} else {
return Err(ParseColorError);

View file

@ -1,3 +1,7 @@
// The code that works on text pays attention to unicode in this file by working in graphemes
// instead of byte indexes. This is important for languages that use double-width characters.
#![allow(clippy::string_slice)]
use std::{collections::VecDeque, vec::IntoIter};
use unicode_segmentation::UnicodeSegmentation;