I’d say it’s really unclear what kind of help you are asking for here. The Rust compiler is often described a being very helpful. Thus, if you don’t want any feedback on what to do to make your code compile on how to get your code to compile, you’re essentially opting out of the most helpful kind of feedback.
Also, in general, lots of tips or feedback on Rust code relates to what the compiler accepts and what it doesn’t, what patterns play nicely with the borrow checker and which don’t, etc… it’s kind-of a precondition to have either code that already compiles, or code that almost works, but you’re struggling with e.g. some borrow-checker errors, in order to get the most meaningful / useful feedback. If it’s all in a state where everything we’d notice when reading your code is things that the compiler already points out anyways, it’s hard to give useful feedback beyond either saying the same thing that rustc
(invoked through cargo
) or clippy
could tell you as well, or telling you to just use these tools yourself (the latter option requiring a lot less time spent on our end).
As @cole-miller said above (pointing out e.g. todo
), making your program compile is not the same as making it work. It’s understandable that you do not want to “make the code work”, but even then you could try to make most of it compile, favorably even with as few warnings or clippy lints firing as possible.
In any case, it’s also entierly understandable that you don’t want to go there (making it compile) with this particular code anymore either; the point where we’re trying to help you is in addressing the question of “how did you get there?”, the advise of @droundy is mostly speaking about how you could/should approach your next Rust project, i.e. try to regularly get back into a state where the code compiles. On the order of minutes… if it has been 10 minutes, or even 20 minutes working on changes, you should consider trying to make the code compile again. If it’s already been a hour, it’s due time to pause everything else and to start working on making everything compile again. There’s probably lots of people that wouldn’t go for 5 minutes without “asking the compiler for help” (which is essentially the same as starting to work on making the code compile again, since that’s the compiler’s main concern when it’s “helping” you).
If you’re referring to unimplemented stuff in your code, add a stub function for it (with todo
), or a stub variable initialized with todo!()
or with some dummy value, or add a stub struct for it (e.g. without any fields and a TODO
comment) if it’s a type. If you have a few functions not passing the borrow checker, comment their function bodies out and add a temporary todo!()
before or after each commented out function body, in order to make sure that the remainder of the program can still compile. (Rust is designed in a way such that the implementation of one function (usually) doesn’t make a difference for whether a different function compiles or not; so if you have a bunch of not-compiling-but-commented-out functions, you can eventually fix them one-by-one, keeping a program that compiles successfully after each step, and never needing to go back to a function that you already got working.) There’s probably more tricks that I can’t think of right now for making unfinished / broken code be able to still compile.
This approach has lots of benefits, to name a few
- the compiler can give useful feedback; but some errors can prevent other (helpful) error messages from being reached in the first place – and even if the one compiler message that could help you right now is still being emitted, it can easily drown in a sea of unrelated errors from other parts of the program.
- refactoring becomes easy. You’ll probably regularly choose one approach over another arbitrarily, or just try something out during programming. When running into a corner where you figure out certain things should’ve been done differently in the first place, refactoring becomes necessary. Once you’ve started refactoring and changed something, it’s insanely useful to let compiler error messages guide on what needs to change as-well…
- IDEs – if you use an IDE, for example something using rust-analyzer, you will only get help like auto-completion, displaying documentation, automatic refactoring, etc… if your code is compiling or in an “almost compiling successfully” state. It can also sometimes be useful to generate documentation locally, which also doesn’t work on too-broken code (generally, rustdoc ignores function bodies, but besides those, many other things must not be broken in order for you to successfully generate documentation). Running
cargo doc --open
locally can help you get an overview over your own modules, types, and functions, and it also includes local documentation of all your dependencies which has super useful implication like being able to search through all your dependencies at once with a single search bar.