rust-lang/vscode-rust

simple features without cargo

1m188 opened this issue · 3 comments

1m188 commented

i want to write a simple practice with quicksort in rust, it may be a small single file, and i dont want to make a dir and write a cargo.toml file for it, it's tedious, and may be i will write many files like this, i dont want to do so many things for such a small file, but i also want the functions with the plugin like autocomplete, diagnostic, format and so on, so are there any ways can let it work without cargo? I wrote c++ before, as far as i know, there are some plugins like clangd can provide these functions without any build tools for just one single file, and I want to migrate my habit to rust, are there any good ways?

You don't have to write the Cargo.toml by hand, cargo new will generate one automatically.

This extension is unmaintained, and https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer is recommended instead. The latter does have some support for for single-file editing, but it's not perfect, and I'd still strongly advise you to set up a cargo project instead.

1m188 commented

In fact, I will write many many files and every one has an entry "fn main{...}", and i want to make them in a folder directly, i want to organize them by my own ways, may be there are some obscure with my description, in fact i want write a file without any build tools, and with minimal necessary functionality which can improve coding experience only. But still thank you, i will try your advice.

What I've done before was:

mod day1; // in `src/day1.rs`
mod day2;
/// ...

fn main() {
    // day1::main();
    day2::main();
}

Rust isn't like C++ where you can equally pick GNU make, CMake, meson, VCBuild or whatever. Indeed, you can compile Rust -- even Rust dependencies -- without cargo, but it won't be pleasant and you'll lose some build performance once you have dependencies (because cargo and rustc support pipelining when used together). And cargo is more precise (you don't need to clean and rebuild to be sure) than a lot of the Makefiles I've seen.

And at some point you might want unit tests, which are much nicer to use with cargo.