You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: 0042-trapping-rain-water.rs
    path of file: ./repos/NeetCode-Solutions/02_Two_Pointers/05_Trapping_Rain_Water
    
    the code of the file until where you have to start completion: /*
Problem: LeetCode 42 - Trapping Rain Water

Key Idea:
The key idea is to calculate the amount of trapped rainwater at each position by finding the maximum height on the left and right sides.

Approach:
1. Create two arrays, `max_left` and `max_right`, to store the maximum height on the left and right sides of each position.
2. 
    
    pub fn trap(height: Vec<i32>) -> i32 {
        let n = height.len();
        if n == 0 {
            return 0;
        }

        let mut max_left = vec![0; n];
        let mut max_right = vec![0; n];

        max_left[0] = height[0];
        for i in 1..n {
            max_left[i] = max_left[i - 1].max(height[i]);
        }

        max_right[n - 1] = height[n - 1];
        for i in (0..n - 1).rev() {
            max_right[i] = max_right[i + 1].max(height[i]);
        }

        let mut trapped_water = 0;
        for i in 0..n {
            trapped_water += (max_left[i].min(max_right[i]) - height[i]) as i32;
        }

        trapped_water
    }