Moving from Java to Rust?

Folks,

apologies if this question is too basic: I've been a long term "server-sided" developer, spent the last couple of years using Java and frameworks such as Dropwizard to build RESTful services. Stumbled across Rust in a project and wonder whether anyone out here with a similar experience can provide me with a good pointer / piece of "getting started" documentation to quickly get along with all the specifics of Rust (build tools, frameworks for REST, ...)? After taking a first quick dive I feel pretty much overwhelmed by what's "new"... :wink:
TIA and all the best,
Kristian

1 Like

I am not sure if any "to rust from java" thing exist.

rest framework: iron (nowhere near sophistication of java frameworks, but gets the job done with some DIY plumbing)
build tools: just cargo, there is no need for anything else.

I'd suggest to write hello world, get familiar with cargo, follow examples from iron, and that's it.
There really isn't that much to learn tooling wise.

1 Like

There's this general project: https://github.com/mgattozzi/rust-from-lang
In their External section they have two Links about Java.

Concerning tooling you will probably have to change everything. The dependency repository is crates.io and is automatically used by the Rust build tool cargo. On the IDE and REST framework fronts, I can't give you any advice. I hope you find your way into Rust. It is a lot of fun :slight_smile:

1 Like

Thanks all for your hints. Basically, yes, I'm mostly aware or rather supposed I'd have to go through quite a learning curve. That's perfectly fine - just looking for where to pull "first" to get the xx% of fundamental stuff out of the way (project structure, folder layout, how to set up an IDE, how to move stuff out of an IDE into a testing system). I'll follow your links and see where it gets me. Maybe I'll be back here. :slight_smile:
Thanks again,
Kristian

I'm sort of in a similar boat; I've been thinking of making the switch from Scala to Rust.

I can share with you my experience so far.

As far as IDEs go, all I've tried so far is IntelliJ using the intellij-rust plugin. Refactoring works, as well as syntax error highlighting, but sadly there's no auto-complete at this time (EDIT: I'm wrong about this, I needed to update my plugin). From what I've seen emacs-racer, the Rust module for emacs, is more mature. However if you don't already know emacs, it has its own learning curve which can be distracting.

You can put unit tests in a tests directory, and run them with cargo test. IntelliJ pretty prints the output just like JUnit. You can also write tests in your documentation, somewhat similar to Python's doctest built-in module.

The BouncyCastle Java library lets you make a self-signed X.509 certificate programmatically and in memory, which you can then hand to a client. This is nice for testing IMO, since I don't like having self-signed certificates lying around. I couldn't figure out a way to do this in Rust.

I also couldn't figure out a way of starting an iron server in a thread so I could run tests. It doesn't look like the repo has any tests, which is a bummer.

As far as IDEs go, all I've tried so far is IntelliJ.

Are you referring to the intellij-rust plugin?

but sadly there's no auto-complete at this time

because in my experience the auto-complete works quite well. It's definitely not 100%, but much of time the type inference works.

For example, this toy example works in intellij-rust:

struct MyStuct {
    a: u32,
    b: u32,
}

fn main() {
    let my_struct = MyStuct { a: 1, b: 2 };
    my_struct.  // auto-completes `a` and `b`
}
2 Likes

@johnthagen Thanks, looks like I needed to upgrade my plugin. I've edited my previous reply.

You can check out the Rocket web framework. It's pretty interesting.

As for learning Rust itself, you should reference the new book.

For installing Rust, after you've installed rustup you're pretty much good to go.

You can just execute the following to get a good environment setup

rustup component add rust-src
rustup component add rust-docs
rustup toolchain install nightly
cargo +nightly install racer
cargo +nightly install clippy

Then you can just type rustup docs in the command line to open an offline version of Rust's documentation website, and configure your IDE to use Racer and Clippy.

2 Likes