rustHow to declare a matrix in Rust?
A matrix can be declared in Rust using a two-dimensional array. The following example code block shows how to declare a 3x3 matrix:
let matrix: [[i32; 3]; 3] = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
The output of the above code is:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
The code consists of the following parts:
let
: This is a keyword used to declare a variable.matrix
: This is the name of the variable.[[i32; 3]; 3]
: This is the type of the variable. It is a two-dimensional array of typei32
with 3 elements in each row.[...]
: This is the value of the variable. It is an array of 3 arrays, each containing 3 elements.
Helpful links
Related
More of Rust
- How to replace a capture group using Rust regex?
- How to match whitespace with a regex in Rust?
- How to match a URL with a regex in Rust?
- How to split a string with Rust regex?
- How to get a capture group using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use regex lookahead in Rust?
- How to get all matches from a Rust regex?
- How to parse JSON string in Rust?
- Hashshet example in Rust
See more codes...