some more stuff

This commit is contained in:
Jasper Ras 2025-08-21 21:48:08 +02:00
parent cc2f1b67a8
commit eb9773627e
12 changed files with 150 additions and 0 deletions

7
ch4/slices/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "slices"
version = "0.1.0"

6
ch4/slices/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "slices"
version = "0.1.0"
edition = "2024"
[dependencies]

18
ch4/slices/src/main.rs Normal file
View file

@ -0,0 +1,18 @@
fn first_word(s: &String) -> usize {
let bytes = s.as_bytes();
for (i, &item) in bytes.iter().enumerate() {
if item == b' ' {
return i;
}
}
s.len()
}
fn main() {
let mut s = String::from("hello world");
let word = first_word(&s);
println!("{}", word);
s.clear();
}