Startseite | Impressum
$$ \newcommand{\R}{\mathbb{R}} \newcommand{\N}{\mathbb{N}} \newcommand{\C}{\mathbb{C}} \newcommand{\P}{\mathbb{P}} \newcommand{\Q}{\mathbb{Q}} $$

Strings und Slices

Slices sind ein Prinzip in Rust mit denen Strings bearbeitet werden.

fn main() {
    let text = String::from("Hello, Rust learner!");
    let sub = first_part(&text);
    println!("Original: {}", text);
    println!("Sliced: {}", sub);
}

fn first_part(s: &str) -> &str {
    // Return the first 5 characters (for example)
    &s[..5]
}