Sign in
android
/
toolchain
/
rustc
/
15a6560abe9880705f51d219c1fa94f880dbaf35
/
.
/
src
/
doc
/
book
/
listings
/
ch04-understanding-ownership
/
no-listing-18-first-word-slice
/
src
/
main.rs
blob: f44a970daa2b85265981c053ee964d372e4e796a [
file
] [
log
] [
blame
]
// ANCHOR: here
fn
first_word
(
s
:
&
String
)
->
&
str
{
let
bytes
=
s
.
as_bytes
();
for
(
i
,
&
item
)
in bytes
.
iter
().
enumerate
()
{
if
item
==
b
' '
{
return
&
s
[
0.
.
i
];
}
}
&
s
[..]
}
// ANCHOR_END: here
fn
main
()
{}