mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
406 B
22 lines
406 B
// ANCHOR: here
|
|
fn first_word(s: &String) -> usize {
|
|
// ANCHOR: as_bytes
|
|
let bytes = s.as_bytes();
|
|
// ANCHOR_END: as_bytes
|
|
|
|
// ANCHOR: iter
|
|
for (i, &item) in bytes.iter().enumerate() {
|
|
// ANCHOR_END: iter
|
|
// ANCHOR: inside_for
|
|
if item == b' ' {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
s.len()
|
|
// ANCHOR_END: inside_for
|
|
}
|
|
// ANCHOR_END: here
|
|
|
|
fn main() {}
|