4 ms·
Rust is a really fantastic language but trivial examples can be misleading. We run a Rust app in production at ChartMogul. Real life Rust business logic is muc
by jashmatthews 8y ago
Rust is a really fantastic language but trivial examples can be misleading. We run a Rust app in production at ChartMogul.
Real life Rust business logic is much, much gnarlier than in a GCed language like JS. You need to manage memory so you need to deal with references and deref, lifetimes, Box, Cell, ARC etc.
For an open source example of what kind of complexity arises in real life check out crates.io:
https://github.com/rust-lang/crates.io/blob/363b9e036b2ba5d802ab6bd7dbca2f945fe35dde/src/controllers/krate/publish.rs#L25 https://github.com/rust-lang/crates.io/blob/363b9e036b2ba5d8...
- qaq 8y agoIt's not really using web framework right ? For many web apps the business logic is pretty much manipulating DB state.
- jashmatthews 8y agoGetting data from the request to the DB requires dealing with all those memory management issues. The Rust compiler is amazingly helpful but the complexity is still there.
- marton78 8y agoWow. Coming from a C++ background, why is it necessary to first dereference, then reference again? That is, `&foo`? And why is triple dereferencing needed? There are some `&foo`. I thought I had read somewhere that Rust does auto-ref/auto-deref...
- steveklabnik 8y ago> why is it necessary to first dereference, then reference again? This is a conversion; * calls the Deref trait. This is used by smart pointers to return the type inside the smart pointer, so for example, Box<T> is kinda like uniq_ptr<T>. So if foo is a Box<T>, then * foo is a T, and & * foo is a &T. Does that make sense? > And why is triple dereferencing needed? This can happen in generic contexts, sometimes, you end up with a &&String, so if foo is one of those, * foo is a &String, * * foo is a String, * * * foo is a str, and & * * * foo is a &str. (HN formatting does not like this, haha) That's what's happening here. > I thought I had read somewhere that Rust does auto-ref/auto-deref... Only for method calls, that is, foo.bar() will attempt to auto ref/deref foo.