Skip to content

4. Read user input #2

@prophen

Description

@prophen

https://github.com/prophen/intro-to-rust/blob/nikema's-notes/exercises/04.md

  • Memory safety is the guarantee that Rust gives us
  • ownership means values get passed and when the value is no longer needed it is dropped
  • borrowing is passing by reference
String -> &String -> &str
Value       Reference    String Slice?

use std::io;

fn main() {
    println!("Hi, what's your name? ");
    let mut name = String::new();
    io::stdin().read_line(&mut name).unwrap();
    println!("Hello {}", name);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions