ends_with
, use a char
instead 5// note: checking the side didn't seem to make a difference in the benchmarks
6fn game_playthrough_test(pgn: &str) -> Game {
7 let mut game = Game::new();
8 let moves = pgn.split_whitespace().filter(|s| !s.ends_with(".")); 9
10 for m in moves {
11 let mv = ChessMove::from_san(&game.current_position(), m).unwrap();
ends_with
, use a char
instead33 boards.push(Board::default());
34
35 pgn.split_whitespace()
36 .filter(|s| !s.ends_with("."))37 .fold(Game::new(), |mut g, m| {
38 g.make_move(ChessMove::from_san(&g.current_position(), m).expect("Valid SAN Move"));
39 boards.push(g.current_position());
Certain str
functions, such as .split()
and .find()
work on patterns that
accept both string literals as well as characters. When using such functions,
prefer char
s over single-character string literals as they are more
performant.
Replace the single-character string literal with a char
.
let x = "hello, world";
x.find("o"); // single-character str
let x = "hello, world";
x.find('o'); // use a char instead