Following up on And here we go - more Rust By Example I had some fun munging a string into elements of an array in Rust.
This is with what I ended up: -
fn main() {
let image_string: &str = "docker.io/davidhay1969/hello-world-nginx:latest";
let mut image_array: [&str; 4] = ["registry", "namespace", "repository", "tag"];
let mut index = 0;
for _part in image_string.split(&['/', ':'][..]) {
image_array[index] = _part;
index = index + 1;
}
for _i in 0..image_array.len() {
println!("Index {} value {}",_i,image_array[_i]);
}
}
let image_string: &str = "docker.io/davidhay1969/hello-world-nginx:latest";
let mut image_array: [&str; 4] = ["registry", "namespace", "repository", "tag"];
let mut index = 0;
for _part in image_string.split(&['/', ':'][..]) {
image_array[index] = _part;
index = index + 1;
}
for _i in 0..image_array.len() {
println!("Index {} value {}",_i,image_array[_i]);
}
}
and this is how it looks when I run it: -
cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_world`
Index 0 value docker.io
Index 1 value davidhay1969
Index 2 value hello-world-nginx
Index 3 value latest
Running `target/debug/hello_world`
Index 0 value docker.io
Index 1 value davidhay1969
Index 2 value hello-world-nginx
Index 3 value latest
noting that I'm doing this in Microsoft Visual Studio Code
I did get some useful inspiration for this from, amongst others: -
Now to add this functionality into my work with Kata Containers ..... YAY!