✅ Rust Solution
\nimpl Solution {\n    pub fn semi_ordered_permutation(nums: Vec<i32>) -> i32 {\n        let n = nums.len();\n        let mut nums = nums;\n\n        let mut mi
```\nimpl Solution {\n    pub fn semi_ordered_permutation(nums: Vec<i32>) -> i32 {\n        let n = nums.len();\n        let mut nums = nums;\n\n        let mut min_num_operations = 0;\n        while !(nums[0] == 1 && nums[n - 1] == n as i32) {\n            for i in 0..n {\n                let num = nums[i];\n                if num == 1 && i > 0 {\n                    let temp = nums[i - 1];\n                    nums[i - 1] = num;\n                    nums[i] = temp;\n                    min_num_operations += 1;\n                } else if num == n as i32 && i < n - 1 {\n                    let temp = nums[i + 1];\n                    nums[i + 1] = num;\n                    nums[i] = temp;\n                    min_num_operations += 1;\n                }\n            }\n        }\n\n        min_num_operations\n    }\n}\n```
['Rust']