How do I run only a specific file other than

I would like to create a new file in the current project just to test this example. The workspace has the default structure after cargo new project. I just want to test this somewhere other than in Because I already have code there. How can I do this with cargo? I know I can do rustc to execute and rustc --test to test it.

cargo test will run every function with a #[test] attribute, and every main in the tests folder. These are unit and integration tests, respectively.

Learn more here: Tests - The Cargo Book

If you want to have a second program instead of using the test runner, you can put the code in src/bin/ and then run it with cargo run --bin example.