DEV Community

artemismars
artemismars

Posted on

rust day 1

use std::io;
Enter fullscreen mode Exit fullscreen mode

std is a standard library.
:: syntax indicates that io is an associated function.

let mut guess = String::new();
Enter fullscreen mode Exit fullscreen mode

:: syntax indicates that new is an associated function.
Associated function means a function that's implemented on a type.
It returns a new instance of String.
It's a empty string.

use std::io;

fn main() {
    let mut guess = String::new();
    io::stdin()
        .read_line(&mut guess)
        //...
}
Enter fullscreen mode Exit fullscreen mode

If we hadn't imported io library with use std::io at the beginning of the program, we could still use the functoin stdin() by writing this function call as std::io::stdin().
The stdin function returns an instance of std::io::Stdin, which is a type that represents a handle to the standard input for your terminal.

Top comments (0)