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: -
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
Running `target/debug/hello_world`
Index 0 value docker.io
Index 1 value davidhay1969
Index 2 value hello-world-nginx
Index 3 value latest
No comments:
Post a Comment