2019-02-26 10:34:09 Rust

おしゃれなコードを書きたかっただけなのに可読性の低さよ。

Copy Copied! Full
let mut positions: Vec<Position> = match piece_on_board { None => Vec::new(), Some(ref piece) => { let move_rule_iter = piece.piece.move_rules.iter(); move_rule_iter .map(|move_rule| match move_rule { MoveRule::Step { step_length, direction, } => vec![Position { x: &src_position.x + (piece_owner_direction * direction.offset.x_offset * step_length), y: &src_position.y + (piece_owner_direction * direction.offset.y_offset * step_length), }], MoveRule::Jump(OffSet) => vec![Position { x: &src_position.x + (piece_owner_direction * OffSet.x_offset), y: &src_position.y + (piece_owner_direction * OffSet.y_offset), }], MoveRule::GoStraight(Direction) => { let mut result = Vec::new(); let mut x_offset = Direction.offset.x_offset; let mut y_offset = Direction.offset.y_offset; while 1 <= (&src_position.x + piece_owner_direction * x_offset) && (&src_position.x + piece_owner_direction * x_offset) <= board.width && 1 <= (&src_position.y + piece_owner_direction * y_offset) && (&src_position.y + piece_owner_direction * y_offset) <= board.height { result.push(Position { x: &src_position.x + (piece_owner_direction * x_offset), y: &src_position.y + (piece_owner_direction * y_offset), }); x_offset = x_offset + Direction.offset.x_offset; y_offset = y_offset + Direction.offset.y_offset; } result } }) .fold(Vec::new(), |mut acc, mut v| { acc.append(&mut v); acc }) } };
おしゃれなコードを書きたかっただけなのに可読性の低さよ。