Rust solution
Code\n\nimpl Solution {\n    pub fn min_max_difference(mut num: i32) -> i32 {\n        let (mut max_val, mut min_val) = (0, 0);\n        let (mut max_dig_rm, mu
# Code\n```\nimpl Solution {\n    pub fn min_max_difference(mut num: i32) -> i32 {\n        let (mut max_val, mut min_val) = (0, 0);\n        let (mut max_dig_rm, mut min_dig_rm) = (-1, -1);\n        let p = (num as f64).log10() as u32;\n        let mut div = 10_i32.pow(p);\n\n        for _ in 0..=p {\n            let digit = num / div;\n            max_val *= 10;\n            min_val *= 10;\n\n            max_val += match (max_dig_rm, digit) {\n                (-1, x) => {\n                    if x != 9 {\n                        max_dig_rm = x\n                    }\n                    9\n                }\n                (x, y) if x == y => 9,\n                _ => digit,\n            };\n\n            min_val += match (min_dig_rm, digit) {\n                (-1, x) => {\n                    if x != 0 {\n                        min_dig_rm = x\n                    }\n                    0\n                }\n                (x, y) if x == y => 0,\n                _ => digit,\n            };\n\n            num %= div;\n            div /= 10;\n        }\n\n        max_val - min_val\n    }\n}\n\n```
['Math', 'Iterator', 'Rust']