2023-04-20 14:37:15 +00:00
|
|
|
//@edition:2018
|
2021-10-29 03:32:37 +00:00
|
|
|
|
|
|
|
#![warn(clippy::needless_splitn)]
|
|
|
|
#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)]
|
|
|
|
|
|
|
|
extern crate itertools;
|
|
|
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use itertools::Itertools;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let str = "key=value=end";
|
|
|
|
let _ = str.splitn(2, '=').next();
|
|
|
|
let _ = str.splitn(2, '=').nth(0);
|
|
|
|
let _ = str.splitn(2, '=').nth(1);
|
|
|
|
let (_, _) = str.splitn(2, '=').next_tuple().unwrap();
|
|
|
|
let (_, _) = str.splitn(3, '=').next_tuple().unwrap();
|
|
|
|
let _: Vec<&str> = str.splitn(3, '=').collect();
|
|
|
|
|
|
|
|
let _ = str.rsplitn(2, '=').next();
|
|
|
|
let _ = str.rsplitn(2, '=').nth(0);
|
|
|
|
let _ = str.rsplitn(2, '=').nth(1);
|
|
|
|
let (_, _) = str.rsplitn(2, '=').next_tuple().unwrap();
|
|
|
|
let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap();
|
2022-04-04 15:30:38 +00:00
|
|
|
|
|
|
|
let _ = str.splitn(5, '=').next();
|
|
|
|
let _ = str.splitn(5, '=').nth(3);
|
|
|
|
let _ = str.splitn(5, '=').nth(4);
|
|
|
|
let _ = str.splitn(5, '=').nth(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn _question_mark(s: &str) -> Option<()> {
|
|
|
|
let _ = s.splitn(2, '=').next()?;
|
|
|
|
let _ = s.splitn(2, '=').nth(0)?;
|
|
|
|
let _ = s.rsplitn(2, '=').next()?;
|
|
|
|
let _ = s.rsplitn(2, '=').nth(0)?;
|
|
|
|
|
|
|
|
Some(())
|
|
|
|
}
|
|
|
|
|
2022-11-19 12:50:02 +00:00
|
|
|
#[clippy::msrv = "1.51"]
|
2022-04-04 15:30:38 +00:00
|
|
|
fn _test_msrv() {
|
|
|
|
// `manual_split_once` MSRV shouldn't apply to `needless_splitn`
|
|
|
|
let _ = "key=value".splitn(2, '=').nth(0).unwrap();
|
2021-10-29 03:32:37 +00:00
|
|
|
}
|