これは、cのコードと同様に、錆の関数の関数です。

[さび]
`` `
fn matrix_from_normal（正常：＆[f32; 3]） - > [[f32;3];3] {
    MUTを結果とさせます：[[f32;3];3] = [[0F32;3];3];
    let length =（normal [0] * normal [0] + normor [1] * normal [1] + normal [2] * ermorm [2]）。sqrt（）as f32;
    INV_LENGTH =（1F32） / LEENGTH;
    result [0] [0] = normal [0] * inv_length;
    result [0] [1] = normal [1] * inv_length;
    result [0] [2] = normal [2] * inv_length;
    
    result [1] [0] = -normal [1] * inv_length;
    result [1] [1] = normal [0] * inv_length;
    結果[1] [2] = 0F32;
    
    result [2] [0] = -normal [2] * inv_length;
    結果[2] [1] = 0f32;
    result [2] [2] = normal [0] * inv_length;
    
    返品結果;
}
`` `
Вот код функции на Rust, аналогичный коду на C:

[Rust]
```
fn matrix_from_normal(normal: &[f32; 3]) -> [[f32; 3]; 3] {
    let mut result: [[f32; 3]; 3] = [[0f32; 3]; 3];
    let length = (normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]).sqrt() as f32;
    let inv_length = (1f32) / length;
    result[0][0] = normal[0] * inv_length;
    result[0][1] = normal[1] * inv_length;
    result[0][2] = normal[2] * inv_length;
    
    result[1][0] = -normal[1] * inv_length;
    result[1][1] = normal[0] * inv_length;
    result[1][2] = 0f32;
    
    result[2][0] = -normal[2] * inv_length;
    result[2][1] = 0f32;
    result[2][2] = normal[0] * inv_length;
    
    return result;
}
```