Calculating average value of points around given point in a wider field
We don't need an x_range. We need a range of proper indices over space, as it enables us to use space[start..stop].iter().sum(). We need a combination of x_range and y_range.
So let's start by building one from hand:
fn local_average((x, y): (i32, i32), n: i32, (width, height): (i32, i32), space: &amp;[i32]) -&gt; i32 {
    let y_range = cmp::max(y - n, 0)..cmp::min(y + n + 1, height);
    let x_range = cmp::max(x - n, 0)..cmp::min(x + n + 1, width);

    let size = (x_range.end - x_range.start) * (y_range.end - y_range.start);
    let mut total: i32 = 0;

    for yi in y_range {
        let start = (yi * width + x_range.start) as usize;
        let end = start + ((x_range.end - x_range.start) as usize);

        total += space[start..end].iter().sum::&lt;i32&gt;();
    }

    total / size
}

Note that the code above was formatted by rustfmt. The rustfmt-style is very common in Rust projects, and several projects reject contributions until they are properly formatted. For cargo based projects use cargo fmt.
Either way, we now replaced the inner loop by a single sum(), which is more explicit about our goal. This is also a mixture of both your code styles. At this point, we might as well replace x_range by x_size, but that's a question of style.
For an easier use of local_average, we could introduce type Point = (i32, i32) and type Rect = (i32, i32), however, again, that's a matter of preference.