Rust translated, 8ms 100%
rust\nimpl Solution {\n    pub fn minimum_moves(mut grid: Vec<Vec<i32>>) -> i32 {\n        use std::collections::VecDeque;\n\n        fn can_rotate(g: &[Vec<i32
```rust\nimpl Solution {\n    pub fn minimum_moves(mut grid: Vec<Vec<i32>>) -> i32 {\n        use std::collections::VecDeque;\n\n        fn can_rotate(g: &[Vec<i32>], r: i32, c: i32) -> bool {\n            r < g.len() as i32 - 1\n                && c < g[0].len() as i32 - 1\n                && (g[r as usize + 1][c as usize] & 1) == 0\n                && (g[r as usize][c as usize + 1] & 1) == 0\n                && (g[r as usize + 1][c as usize + 1] & 1) == 0\n        }\n\n        fn can_go_down(g: &[Vec<i32>], r: i32, c: i32, vertical: bool) -> bool {\n            if vertical {\n                r < g.len() as i32 - 2 && (g[r as usize + 2][c as usize] & 1) == 0\n            } else {\n                r < g.len() as i32 - 1\n                    && (g[r as usize + 1][c as usize] & 1) == 0\n                    && (g[r as usize + 1][c as usize + 1] & 1) == 0\n            }\n        }\n\n        fn can_go_right(g: &[Vec<i32>], r: i32, c: i32, vertical: bool) -> bool {\n            if !vertical {\n                c < g[0].len() as i32 - 2 && (g[r as usize][c as usize + 2] & 1) == 0\n            } else {\n                c < g[0].len() as i32 - 1\n                    && (g[r as usize][c as usize + 1] & 1) == 0\n                    && (g[r as usize + 1][c as usize + 1] & 1) == 0\n            }\n        }\n\n        let mut steps = 0;\n        let mut q = VecDeque::<(i32, i32, bool)>::new();\n        q.push_back((0, 0, false));\n        while !q.is_empty() {\n            let size = q.len();\n            for _ in 0..size {\n                let (r, c, vertical) = q.pop_front().unwrap();\n                if r == grid.len() as i32 - 1 && c == grid[0].len() as i32 - 2 {\n                    return steps;\n                }\n                if grid[r as usize][c as usize] & (if vertical { 2 } else { 4 }) == 0 {\n                    grid[r as usize][c as usize] |= if vertical { 2 } else { 4 };\n                    if can_go_down(&grid, r, c, vertical) {\n                        q.push_back((r + 1, c, vertical));\n                    }\n                    if can_go_right(&grid, r, c, vertical) {\n                        q.push_back((r, c + 1, vertical));\n                    }\n                    if can_rotate(&grid, r, c) {\n                        q.push_back((r, c, !vertical));\n                    }\n                }\n            }\n            steps += 1;\n        }\n        -1\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_minimum_moves() {\n        assert_eq!(\n            Solution::minimum_moves(vec![\n                vec![0, 0, 0, 0, 0, 1],\n                vec![1, 1, 0, 0, 1, 0],\n                vec![0, 0, 0, 0, 1, 1],\n                vec![0, 0, 1, 0, 1, 0],\n                vec![0, 1, 1, 0, 0, 0],\n                vec![0, 1, 1, 0, 0, 0]\n            ]),\n            11\n        );\n    }\n\n    #[test]\n    fn test_minimum_moves_02() {\n        assert_eq!(\n            Solution::minimum_moves(vec![\n                vec![0, 0, 1, 1, 1, 1],\n                vec![0, 0, 0, 0, 1, 1],\n                vec![1, 1, 0, 0, 0, 1],\n                vec![1, 1, 1, 0, 0, 1],\n                vec![1, 1, 1, 0, 0, 1],\n                vec![1, 1, 1, 0, 0, 0]\n            ]),\n            9\n        );\n    }\n}\n```
[]