I am on this page The Slice Type - The Rust Programming Language
And this is my code:
fn main()
{
let x = String::from("He");
let y = x.as_bytes();
for (i, &items) in y.iter().enumerate()
{
if items == b'H'
{
println!("Found H at index {}", i);
}
}
}
In variable y I have converted x as a bytes. In my understanding as_bytes() is a function that converts the String into an array of characters and then converts it into u8, am I correct?
So is there another way to just index the String without having to convert it to anything else? And additionally is it possible to instead convert it to a character?
