Rust learning: lessons, notes, and exercise crates

This commit is contained in:
2026-09-06 23:59:08 +07:00
commit 6ddf41aa81
119 changed files with 10873 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "slice"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "slice"
version = "0.1.0"
edition = "2024"
[dependencies]
+19
View File
@@ -0,0 +1,19 @@
fn main() {
let mut s = String::from("hello world");
let word = first_word(&s);
println!("{word}");
s.clear();
}
fn first_word(s: &str) -> &str {
let bytes = s.as_bytes();
for (i, &item) in bytes.iter().enumerate() {
if item == b' ' {
return &s[..i];
}
}
&s[..]
}