i wonder whether it is possible to easily build single .rs file that uses external "libraries", like structopt from Rust By Example - Is it possible to use some C language equivalent of:
(no C integration to be used in Rust, just as a comparison of lib being used in C)
without need to have all the project/crate/module files/structure?
For quick introductory experiments and single file tiny apps, it seems over-complicated to create project structure all the time, with all the toml, main.rs, etc.
I'd prefer to use rustc directly, with ability to tell it where/how to find "used" Rust libraries...
Trying to google stuff up (and not knowing correct terms most probably yet), i end in various cargo tutorials and all the file creation manuals, which i hope to be able to skip/not use...
thank you for direction, i need to go through rustc book i guess, though i hoped that it would be mentioned as one of common items for newcomers to be able to run simple apps with common "imports"...
i still get the same error when i try to link to a directory that contains structopt-0.3.17.crate downloaded "somehow" when i built the file via full project structure...
*.crate files are just a gzip-ed bundle of the source code. It needs to be unpacked, then build, and finally linked into your application.
That's what cargo does for you.
Of course you could do that manually, but it involves passing a lot of flags to several invocations of rustc
thanks for pointers, ill grok through the book and post here later, if i get my wanted solution for the curious... maybe i jumped into build customizations too soon on my Rust path...
Learning rust first without cargo is a reasonable approach, as long as you don’t mind sticking to the faciities that std provides or that you write yourself. It’s what I did and it’s served me well, but it’s certainly not for everyone.
If you want to know which rustc invocation cargo uses you can run cargo build --verbose on such a project.
I did that, build a small tool and blogged about it.
I'd say "quick" is quite colored by the C expectations, and doesn't match what's actually quick in the Rust world. In Rust running rustc directly is the slow, tedious, error-prone way. It's an equivalent of running the C preprocessor, compiler, assembler, archiver, and linker all separately, because the 5-in-1 combined "gcc" command is doing too much.
It's quicker to write cargo new than to write equivalent rustc commands. Even in terms of compile time, running bare rustc it's not saving you time. Cargo is quite smart in the way it uses rustc, and enables parallelized, incremental builds.
The flip side of this is that cargo makes it so easy to add dependencies that you can easily end up building packages you don’t really need to support features you don’t use. Build times for my copy-and-paste prototypes are significantly faster than the equivalent version that uses popular crates.
Of course, this advantage goes away as soon as I need something really complex.