I'm quite new to Rust. I wanted to print someones name after they input it which I successfully did by using:
use std::io;
fn main() {
let mut name = String::new();
io::stdin().read_line(&mut name).expect("Failed to read line");
name = name.trim().to_string();
print!("Hello {}!", name)
}
But instead of doing that everytime I wanted to get input, I thought it would be a better idea to create a module for it (for general usage, so not just for input)
So I made a file called "custom.rs" (couldn't think of a good name) which contains:
use std::io;
pub fn input() -> std::string::String {
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
input = input.trim().to_string();
input
}
But apparently I can't do it this way, it returns the error: error[E0658]: access to extern crates through prelude is experimental (see issue #44660)
How would I be able to do this so that I can do the following from main.rs?
mod custom;
fn main() {
println!("What is your name?");
//let mut name = String::new();
let mut name = custom::input();
print!("Hello {}!", name);
}