I started learning Rust lately. Kind of interesting but more to learn. Here is the program that help to get the input from user in console. I am sure this might help you.
![Get the input](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2021/10/Rust_programming_language_black_logo.svg_.png?resize=500%2C400)
![Get the input](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2021/10/Rust_programming_language_black_logo.svg_.png?resize=500%2C400)
![Get the input](https://i0.wp.com/chandanbhagat.com.np/wp-content/uploads/2021/10/Rust_programming_language_black_logo.svg_.png?resize=500%2C400)
fn main() {
print!("Please enter some text: ");
let input=get_input();
println!("Input = {0}", input);
}
The following code defines how you write functions.
fn get_input() -> String { return someString;}
Below is the function to get input from the stream and return as string.
fn get_input() -> String {
use std::io::{stdin,stdout,Write};
let mut s=String::new();
let _=stdout().flush();
stdin().read_line(&mut s).expect("Did not enter a correct string");
if let Some('\n')=s.chars().next_back() {
s.pop();
}
if let Some('\r')=s.chars().next_back() {
s.pop();
}
return s;
}