As per previous posts here, I've been working with Kata Containers this past few months, and, as such, have been tinkering with Rust because a core part of the Kata project, namely the kata-agent is written in that particular new ( to me ) language.
Right now, I'm looking at a mechanism to parse container image names, separating out the registry, namespace, repository and tag.
Therefore, I needed to find a way to parse a string e.g. docker.io/davidhay1969/hello-world-nginx:latest into a series of individual strings: -
docker.io
davidhay1969
hello-world-nginx
latest
I started with dot net perls which introduced me to the split() function, and then proceeded from there ...
I then found the Rust By Example site, which allowed me to test out my learnings interactively ...
I started with, of course, Hello World!
// You can test this code by clicking the "Run" button over there ->
// or if you prefer to use your keyboard, you can use the "Ctrl + Enter" shortcut
// This code is editable, feel free to hack it!
// You can always return to the original code by clicking the "Reset" button ->
// This is the main function
fn main() {
// Statements here are executed when the compiled binary is called
// Print text to the console
let full_name="Dave;Hay";
let names = full_name.split(';');
print!("Hello ");
for n in names {
print!("{} ",n);
}
}
No comments:
Post a Comment