Running other file instead of main.rs in same dict

I have been learning rust, so was running the command of cargo run but it was only running the main.rs not second.rs. So my question is that; is there any way for me to second.rs instead of main.rs

You normally shouldn't. main.rs (or lib.rs) is the entry file and everything gets called from there.
But.. you can do it with with cargo or rustc directly:
rustc second.rs
with cargo (make sure it's in src/bin)
cargo run --bin second

Edit: This may help too

Also, it might be useful for you to know how to run an example file.

In the same folder as src, make a folder called examples and add .rs files there. Then you can run them with
cargo run --example second.rs

If the example files use the code in your crate, you will need to add a lib.rs file.

1 Like

I have mostly no main.rs files. Even using lib.rs isn't a requirement for crates. Rust is a very relaxed in using arbitrary names. There is only a requirements for modules, to have matching file name or a directory.