Why I rewrote the mesh generator of Dust3D from Rust to C++ · Dust3D

Dust3D is a quick 3D modeling software. It automatically generates a mesh from nodes drawn by the user. Most of the code is implemented in C++ with Qt, including the UV unwrapper, rigger, pose and motion editor etc, however, the core mesh algorithm was written in Rust. Recently I have rewritten the Rust part. The codebase is pure C++ now.

This is a companion discussion topic for the original entry at https://blogs.dust3d.org/2019/03/13/why-i-rewrote-the-mesh-generator-of-dust3d-from-rust-to-cplusplus/

the hardship is supposed to enable correct code, no? imagine a compiler that is able to check thread safe code, i would be worried if its saying I’m doing the wrong thing. my only experience is with Go where it can know that every thread is aslep.

1 Like

So, pretty much the conclusion is: “I didn’t learn Rust enough so I got back to struggle with what I know…”

Even when you say Rust has what you need, you stubbornly tried to fight it back… Mhmm…

OK… Got it…

Rust encourages code correctness, prevents you from having mem leaks here and there and you pretty much say all the marvels that it offers you get in your way… Ooof.

1 Like

Let’s not be dogmatic here. I applaud the virtues of Rust and am all for static safety. That being said, Rust is not a panacea, nor a one-size-fits-all solution that can be levied against any problem.

As an example of a class of problems where I’ve struggled with Rust - cyclic data structures. I would encourage everyone to try implementing their own binary search tree in Rust (and not using an array representation!). I don’t believe a solution is possible using plain lifetimes. Using Rc<RefCell<T>> quickly becomes tedious with all the cumbersome type annotations, dereferencing, and unwrapping, and even then your program can still panic at runtime if you don’t borrow_mut carefully! What happened to all the static guarantees?

At what point do you just step down into unsafe Rust and munge around pointers? When I got to this point I just started asking myself why I decided not to write this in plain C.

Ultimately, like everything else, the choice of Rust has its associated benefits and drawbacks. Sometimes code just needs to be shipped out the door, at the expense of memory safety and getting off the Rust bandwagon. This is a tradeoff, and the author of this post seems to have put careful thought into their choice of solution.

1 Like

Why not ask some more experienced Rust people for help? Just off the top of my head: for example the guy that is working on the Plexus crate?

That way you keep the existing code, can bump your Rust skills by seeing how a more experienced Rust developr implements /your/ algorithm(s) and still drive the whole thing.

1 Like

Why not to just use raw pointers in Rust?

1 Like

When you implement an algorithm using C++, you can write it down without one second of pause,

Sorry, I cannot, because of so many things to worry about.

you can’t do that in Rust.

But I can. I will just use unsafe pointers to get job done, like in C or C++, then I will wrap unsafe code in safe interface.

But, there is no Qt


Creating binding for C libraries is easy (just use crust). Bindings for C++ is complicated, because C++ has it own runtime, but solvable problem with rithual.

I think we’ll be seeing more and more Rust posts like this. Somewhere in the future someone will invent a new language based on some of the ideas of Rust, and make it much more productive. Until then, it’s just too painful.

Then don’t? I think Rustaceans, and people who are attracted to Rust, are perfectly happy to make sacrifices if it means code correctness.
But I still don’t understand this weird requirements, “what if I WANT to make memory leak huh?? can you language do that?” is just dumb and unproductive

Brave post but not too many Rust zaelots found it yet ;).
Personally I has a similar experience with the uncomfortable syntax. I don’t understand it myself as C++ is my second main language, but I just can’t keep it in my head ;). Started out a couple times now and I still can’t get a “match” right without looking it up. Perhaps I’m getting old… But I dabbled a bit with Elixir and Julia, not even half the time as in Rust, and I had a much easier time writing code without looking up the syntax all the time.

My other issue is that until Rust hasn’t really replaced C++ in many domains, I have to keep both languages in my head for the same use case (together with Python, Bash, Java for my other use cases). With Julia I am in a similar situation. The overhead of using a PyTorch wrapper with Julia doesn’t seem to be worth it. Wrapping the C++ libtorch in Rust to then again wrap it in JNI to run on Android… No.

1 Like