DEV Community

artemismars
artemismars

Posted on

2 1

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay