use std::io;
fn main() {
println!("guess the number.");
println!("plesse input one number");
let mut number = String::new();
io::stdin()
.read_line(&mut number)
.expect("faied!");
// println!("you number is {}", number);
println!("Hello, world!");
}t
(Playground)
Errors:
Compiling playground v0.0.1 (/playground)
warning: function `main` is never used
--> src/lib.rs:3:4
|
3 | fn main() {
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `playground` (lib) generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 1.75s
Linked playground has another (syntax) error, and after fixing it the code runs correctly (that is, on playground, where there's no I/O, it timeouts, and on a local system it should do exactly what is written). What's the problem?
upd: TIL that there is now I/O on playground 
1 Like
Looks like you clicked the "open new thread" link, and maybe you don't have an actual question. In that case, welcome to the community! That said...
...you may have ran Build
instead of Run
. If you meant to run the main
function, you can choose Run from the menu beside the red button in the top left.
(Build
builds the playground code as a library crate, which don't compile into an executable and any function they have called main
is not special. The book has a section about library crates.)
3 Likes
You are building a library crate instead if a binary crate.
I don't think there is a problem.Logically speaking, you are attempting to write a lib library instead of an executable file due to the message given warning:
playground (lib).
For the lib library, the main method written will not be called. You can debug the content written using the [cfg (test)]
command instead of using the main method.
You can further understand by reading the relevant content in the document:Writing Automated Tests - The Rust Programming Language
Put your code with the "main()" function in a file named "src/main.rs". The "src/lib.rs" file is for library code.