W
W
WasTabon2022-01-25 18:38:18
Rust
WasTabon, 2022-01-25 18:38:18

Why write fn main() -> io::Result{ in Rust like this?

use std::io;
 
fn main()  -> io::Result<()>{
     
    let mut input = String::new();
    println!("Введите свое имя: ");
    io::stdin().read_line(&mut input)?;
    println!("Ваш имя: {}", input);
     
    Ok(())
}


Like what is this Result? It is not used anywhere in this code.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2022-01-25
@WasTabon

It is not used anywhere in this code.

Used.
use std::io;
 
fn main()  -> io::Result<()>{
     
    let mut input = String::new();
    println!("Введите свое имя: ");
    io::stdin().read_line(&mut input)?; // Тут
    println!("Ваш имя: {}", input);
     
    Ok(()) // И тут
}

R
Roman Kitaev, 2022-01-25
@deliro

https://qna.habr.com/q/1105214#answer_2097786

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question