Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Haven't used Rust yet, is it kind of similar to Go where any file can simply import and then Go knows how to fetch and build when needed ? And then when you remove the calls (eg during a refactor) the compiler force you to remove the imports too, stopping the infinite bloat caused by "no one really knows if we still need this" that can be common in other language.

I really liked that "dependancy as part of the language and build tool".

Of course, Go still had its own dependancy issues (versionning, availability, ...) that they now work on, but that was a step in a direction I quite liked.



> is it kind of similar to Go where any file can simply import

You declare your crate dependencies in a Cargo.toml file. Rust does proper versioning of dependencies so having a separate manifest is desirable. Within your code you declare the existence of a crate via `extern crate` and then you can use it wherever.

> the compiler force you to remove the imports too

it warns.


Do you know if there are plans for rustfmt to auto-import like gofmt does? In the sense that if a crate is available (in the .toml file) and you reference it, rustfmt will automatically insert the required "import" and "use".


If the compiler gives you an error with a suggestion "You probably need to add `extern crate foo;`" (and it already does in some cases), RLS (i.e., your editor plugin) will be able to automatically add it for you (soon™).


There's been talk of it, but it hasn't been built yet.

It's more likely to be a part of RLS than rustfmt.


This would probably be an RLS thing.

There's a separate tool called rustfix in development that can apply the suggestions given by the compiler, so it could theoretically prompt for these.


Its kind of the reverse. You declare versioned dependencies in the toml file, and (soon) Cargo will add them to rustc so they just show up for your source files. Right now you declare them twice, once in the toml and once in the crate root - ie, you add url = 1.5 in toml, and extern crate url in src/main.rs. There is an RFC coming that will make the extern crate part optional.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: