here is my code
fn main() {
println!("Hello, world!");
let m :String = String::from("Hello world");
let mut x :usize = ret_s(&m);
let slice = &m[..x];
println!("slice ====== {}",slice);
}
fn ret_s(x: &str) -> usize {
let m = x.as_bytes();
let mut m :usize;
for (i,&item) in m.iter().enumerate() {
if item == b' ' {
m = i;
}
}
return m ;
}
error message is
C:\Users\Dell\Desktop\rust\learn\string>cargo build
Compiling string v0.1.0 (file:///C:/Users/Dell/Desktop/rust/learn/string)
error[E0599]: no method named `iter` found for type `usize` in the current scope
--> src\main.rs:13:21
|
13 | for (i,&item) in m.iter().enumerate() {
| ^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.
error: Could not compile `string`.
To learn more, run the command again with --verbose.