16 ms·
Is Rust Web Yet?
- wheresmycraisin 5y agoSo, are there actual uses (not just potential use cases) of webassembly beyond games and crypto-mining?
- kadoban 5y agoUsing the same language for your frontend and backend has a lot of advantages in terms of code reuse and it's potentially easier in terms of the number of skills your team needs.
- jeroenhd 5y agoOne use case I've seen is mostly-safe arbitrary code execution as a service. Because WASM doesn't have a direct method of calling system API functions, you have quite a lot of control over the runtime. Most JS engines are too powerful to just run arbitrary code (especially if they're not run inside a browser) and other tools (LUA etc.) have libraries that usually assume that the program is not executing code from third parties. With many if not most WASM libraries, there is no unmetered networking, there is no I/O, only methods you explicitly write call wrappers for. For tools like Cloudflare Workers, WASM can be used as a format that executes relatively quickly, relatively safely. Most software won't be in a position where you'd want to push third party blobs of code and execute it in the backend, but for some programs (SaaS + custom report generation?) it can be a nice plugin platform. There are, of course, alternatives, but since LLVM and GraalVM compile to WASM, there are tons of languages that can generate a compatible blob. There is something to be said for code reuse, but the speed of the WASM <-> JS bridge to interact with the DOM makes that use case quite difficult to accomplish efficiently.
- devmunchies 5y agoyes. WASI has the potential to replace containerized services (ie. docker, k8s).
- sydthrowaway 5y agoWhat's the best way to learn rust for low latency programming in 2022?
- jeroenhd 5y agoI think most low latency tricks work just as well in Rust as in any language. Shared writeable buffers to keep allocations and such down can be a challenge, but with the right unsafe code (and knowledge of the workings of Rust) you can make them work.
- rozgo 5y agoWe’ve been able to build a mobile/web hybrid ride-sharing app using Yew/GraphQL. A robot Lego-like 3D builder, with Yew interop with ThreeJS. And a full 3D web game with Yew hosting a Bevy game. Everything packed with trunk. It’s still a bit rough around the edges but the Rust benefits more than makes up for it.
- ldiracdelta 5y agoThe api and cli of https://mayhem4api.forallsecure.com/ https://mayhem4api.forallsecure.com/ are written in Rust. Still using react on frontend with REST api written with actix.
- DixieDev 5y ago"Rust has mature and production ready frameworks in Actix Web and Rocket" Why is Rocket considered production ready when it's only just at version 0.5? Similar <1.0 stories can be found on crates for sqlx, rusqlite, and postgres. Am I wrong in assuming the API must be quite stable before it can receive the 'production ready' label?
- whb07 5y agoThat’s correct, the creator has been uber meticulous and methodical in his versioning and using stable Rust parts.
- DixieDev 5y agoI feel like they should probably advertise this fact somewhere, as I couldn't find it in their docs, website, or readme, and it is quite a significant detail.
- api 5y agoRust versioning is different than the custom in lots of other languages. There are lots of perfectly good mature 0.x libraries.
- tempest_ 5y agoRust definitely loves a good zer0ver, for better and worse.
- imranhou 5y agoHow do you debug rust code that has been compiled to we assembly?
- Tade0 5y agoSource maps I suppose.
- solomatov 5y agoThey still don't work very well if you use wasm-bindgen: https://github.com/rustwasm/wasm-bindgen/issues/2389 https://github.com/rustwasm/wasm-bindgen/issues/2389 (consider voting for it). P.S. It's very hard to work without wasm-bindgen, since you have to wrap browser API manually otherwise.
- strictfp 5y agoI'm happy to see some new Rust web frameworks that are doing away with attributes and returning to good old iron programmatic style. I might port some old plugins of mine from iron to Warp or Tide. Any opinions on which one to pick?
- jeroenhd 5y ago> Yes! And it's freaking fast! Going by these benchmarks (click around to find your own use case) Rust is definitely fast, but not (much) faster than many other languages, including Javascript. https://www.techempower.com/benchmarks/#section=data-r20&hw=ph&test=composite https://www.techempower.com/benchmarks/#section=data-r20&hw=... When it comes to JSON serializers, there is a Java framework that is faster than Rust, which is interesting to say the least. When you start comparing actual fully-features frameworks, many Rust libraries even lose their advantage! There are definite benefits to Rust web frameworks (despite the minimal speed diff, Rocket or similar can have less than half the RAM requirements that other languages run into!) but just because Rust compiles to machine code doesn't mean it'll revolutionize your web application. > These provide everything you’d expect from a web framework, from routing and middleware, to templating, and JSON/form handling. One problem I've run into is that I wanted to give Rust a try for a basic CRUD application but the features just weren't built in or available in packages. Some frameworks were missing CSRF, others were missing multipart/form uploads, and so on. Online discussions often end up concluding that "it's easy to write the middleware yourself, see this hacky POC", but this type of code is easy to mess up and easy to break with API upgrades. Tide and Warp seem to have matured quite well, so I guess I'll have to give them a go at some point, but I'm a little sceptical. The status of this issue (https://github.com/http-rs/tide/issues/852 https://github.com/http-rs/tide/issues/852) is a little disheartening...
- 41b696ef1113 5y agoNot that I think those metrics are all that relevant, but can someone explain to me how just-js ranks so highly? Very much defying my expectations in comparison with some of the top representatives of compiled languages.
- jeroenhd 5y agoI honestly don't know. It could be a consequence of the way the test is set up, or how the total score is calculated, or maybe the code was optimized better than other frameworks were. You read see the source of the tests here: https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/JavaScript/just https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast... The SQL code seems quite optimized (manually compiling database packets instead of using a library). Most code seems quite static and very small, so it's probably very quick. I don't think you can actually use the framework like that in practice, though.
- DelaneyM 5y agoThis content, while still accurate (Rust is Web-ready, and all the frameworks listed are excellent!), is missing out a few credible and recent options. In particular I want to shout out for Axum (https://github.com/tokio-rs/axum https://github.com/tokio-rs/axum), from the folks who brought us Tokio. I've been building with it for the past few weeks and have enjoyed every minute. I started with Warp, but ended up struggling a bit with middleware. I tried Axum as a web framework wrapper for tower (https://crates.io/crates/tower https://crates.io/crates/tower), and never ended up bothering to reintegrate back into Warp.
- lucasyvas 5y agoWarp's filters (middleware) were the same reason I left for Axum. Axum is very similar to Warp ergonomically, without the heavy macros and with sane middleware. I think Warp paved the way for Axum in many ways though, so it deserves a lot of credit.
- shepmaster 5y agoDitto with my journey from Warp to Axum. The Rust Playground now uses[1] Axum as its backend and I’ve been pleased with working with the maintainers. [1]: https://github.com/integer32llc/rust-playground/pull/777 https://github.com/integer32llc/rust-playground/pull/777
- tempest_ 5y agoI have been toying around with Axum a bit and it is nice as a web framework. I really appreciate the many examples in the repo. Having come from python (day job) I did hit a screeching halt when it came time to meaningfully interact with a database. It is unfair to compare Rusts current offerings to something as mature as SQLAlchecmy but boy does it slow things down dev wise to be mapping my own types and queries using tokio-postgres. I've looked at Diesel, sqlx and SeaORM but have not yet committed to learning one yet. I've also used Warp for some small web server stuff in the past as well. It is an interesting approach but definitely a little different.
- steve_adams_86 5y ago
- davidwparker 5y agoLooking forward to checking some of these frameworks out. Question- Curious to know what backends / languages would be the fastest for a REST-based PostgreSQL backed API?
- jackblemming 5y agoCan some explain why I always get cult like vibes from the rust community?
- recuter 5y agoBecause C is 50 years old and boring. And Rust is slightly more intellectually demanding and takes longer to get into so has a a smaller monk like comm-- oh my god.
- api 5y agoRust is safe. That is huge. The CVE vulnerability list would be like 1/10 the size if Rust were introduced 30 years ago.
- est31 5y agoI'd argue that Rust is less demanding intellectually than C as you don't have to constantly worry about UB. C is definitely easier to "get into", if by "getting into" you mean writing unmergeable contributions full of unidiomatic code and security vulnerabilities. C's age is not an issue in itself. The programming languages it replaced were ahead of C in many ways. It was a setback from a language design point of view, even 50 years ago.
- jeroenhd 5y agoAh, but there's the trick, you ignore the presence of potential UB and write a lot of complicated code real quick!
- thesuperbigfrog 5y ago>> C's age is not an issue in itself. The programming languages it replaced were ahead of C in many ways. It was a setback from a language design point of view, even 50 years ago. C takes a different approach to how it handles problems that was described well in "The Rise of Worse is Better": "Two famous people, one from MIT and another from Berkeley (but working on Unix) once met to discuss operating system issues. The person from MIT was knowledgeable about ITS (the MIT AI Lab operating system) and had been reading the Unix sources. He was interested in how Unix solved the PC loser-ing problem. The PC loser-ing problem occurs when a user program invokes a system routine to perform a lengthy operation that might have significant state, such as IO buffers. If an interrupt occurs during the operation, the state of the user program must be saved. Because the invocation of the system routine is usually a single instruction, the PC of the user program does not adequately capture the state of the process. The system routine must either back out or press forward. The right thing is to back out and restore the user program PC to the instruction that invoked the system routine so that resumption of the user program after the interrupt, for example, re-enters the system routine. It is called PC loser-ing because the PC is being coerced into loser mode, where loser is the affectionate name for user at MIT. The MIT guy did not see any code that handled this case and asked the New Jersey guy how the problem was handled. The New Jersey guy said that the Unix folks were aware of the problem, but the solution was for the system routine to always finish, but sometimes an error code would be returned that signaled that the system routine had failed to complete its action. A correct user program, then, had to check the error code to determine whether to simply try the system routine again. The MIT guy did not like this solution because it was not the right thing. The New Jersey guy said that the Unix solution was right because the design philosophy of Unix was simplicity and that the right thing was too complex. Besides, programmers could easily insert this extra test and loop. The MIT guy pointed out that the implementation was simple but the interface to the functionality was complex. The New Jersey guy said that the right tradeoff has been selected in Unix -- namely, implementation simplicity was more important than interface simplicity. The MIT guy then muttered that sometimes it takes a tough man to make a tender chicken, but the New Jersey guy didn’t understand (I’m not sure I do either). Now I want to argue that worse-is-better is better. C is a programming language designed for writing Unix, and it was designed using the New Jersey approach. C is therefore a language for which it is easy to write a decent compiler, and it requires the programmer to write text that is easy for the compiler to interpret. Some have called C a fancy assembly language. Both early Unix and C compilers had simple structures, are easy to port, require few machine resources to run, and provide about 50%-80% of what you want from an operating system and programming language. Half the computers that exist at any point are worse than median (smaller or slower). Unix and C work fine on them. The worse-is-better philosophy means that implementation simplicity has highest priority, which means Unix and C are easy to port on such machines. Therefore, one expects that if the 50% functionality Unix and C support is satisfactory, they will start to appear everywhere. And they have, haven’t they? Unix and C are the ultimate computer viruses." Source: https://dreamsongs.com/RiseOfWorseIsBetter.html https://dreamsongs.com/RiseOfWorseIsBetter.html
- Sparkle-san 5y agoAlso see: https://areweguiyet.com/ https://areweguiyet.com/ https://arewegameyet.rs/ https://arewegameyet.rs/
- rustworldview 5y ago
- qchris 5y agoAnd for the machine learning/data science domain: https://www.arewelearningyet.com/ https://www.arewelearningyet.com/
- evandale 5y agohttps://wiki.mozilla.org/Areweyet https://wiki.mozilla.org/Areweyet
- maximilianroos 5y agoHere's an example of how useful webassembly can be: we're at the (fairly early) stages of developing PRQL [1]. Because it's in rust, with WASM we could put a live compiler on a webpage [2], and recompile the PRQL into SQL on every keystroke. There's no server process — it's all built in GitHub Actions, hosted in GitHub pages, and runs in the browser. The whole WASM code is 164 lines (o/w half are comments). [1]: https://github.com/prql/prql https://github.com/prql/prql [2]: https://lang.prql.builders/editor.html https://lang.prql.builders/editor.html
- jph 5y agoAxum is an excellent web framework. I'm writing a tutorial ebook here: https://github.com/joelparkerhenderson/demo-rust-axum/blob/main/demo-rust-axum-by-joelparkerhenderson.pdf https://github.com/joelparkerhenderson/demo-rust-axum/blob/m...
- livinginfear 5y ago> "Yes! And it's freaking fast!" They're surely not talking about compilation times. Admittedly it's been a few years since I tried to build a web stack in Rust, but I felt like I was back in the 1990s dealing with the long compile times on modern hardware. Diesel was such a nightmare to use. It was poorly documented, and took a long time to compile even trivial example projects.
- LAC-Tech 5y agoIn fairness to rust, compiler speed has gotten a lot better. Can't speak for every crate though..
- ripley12 5y agoCompile times are still pretty bad, I recently upgraded from a pretty-new laptop to a blazing-fast desktop (12900K) just for Rust development. But at least they're acceptable now: using the mold linker, incremental builds take 1-2s on a large (~450 crate) project. I agree that there's a lot more work to do before Rust development is pleasant on average hardware. Does anyone know if Cranelift is still going anywhere?
- staticassertion 5y ago> They're surely not talking about compilation times. Correct.
- dralley 5y agoSome web frameworks are much worse about compile times than others. I've heard Actix and Warp are not great at this, and that Axum is much better.
- LAC-Tech 5y agoI spent about the past month learning rust - and decided it just wasn't a usable language for me. I think what it comes down to is that I'm just not that into bondage and discipline from a compiler. Yes, I know, it's trying to make my code 'safe', and I'm horribly cavalier and I should feel bad, but: 1. the borrow checker rejects valid programs, has a lot of corner cases it can't catch, and is in active development 2. people routinely write more inefficient code to satisfy it 3. people routinely freak out about 'unsafe', which is a bit much given the first point Anyway, YMMV. Maybe you're smarter than me, or rust fits your mindset better, or you enjoy asking for help on discord all day, but I am so glad not be using it anymore.
- ReaLNero 5y ago> the borrow checker rejects valid programs Yup, this is the tradeoff you have to make to catch the wide variety of bugs. For personal use, probably not worthwhile, but it definitely pays off for the safety it provides in production contexts. The way I view Rust's philosophy is "it's better to catch bugs at the compile stage than at the execution stage".
- LAC-Tech 5y agoOne charitable way to view Rust's philosophy is that it's better to catch bugs at the compile stage than at the execution stage. In theory yes. In practice, getting to the execution stage was such a slog that it rarely happened. Would have liked it a lot better if the borrow checker had the option to be -Wall instead of -Werror.
- FridgeSeal 5y agoOut of curiosity, what are your preferred language(s) to write in, and what sort of software were you trying to write? > Would have liked it a lot better if the borrow checker had the option to be -Wall instead of -Werror. Wouldn’t this defeat the purpose of the borrow checker and remove the guarantees the language gives you?
- 5y ago
- qualudeheart 5y agoIs Rust Web3 yet?
- muglug 5y agoI've spent the last few months porting the guts of a 100 KLOC PHP command-line utility I wrote to Rust. Thanks to the wonderful Rust documentation it's been a mostly painless endeavour. What I've gained as a result: - execution speed (about 3x faster, single-threaded) - better-documented data structures Things I've lost: - ease of iteration - concise, readable code - really smart type inference - a bunch of time thinking about the borrow checker Quick iteration and concise readable code are much more important in web-land than in system programming land, and those are key reasons why I don't think many will be abandoning interpreted langauges for Rust. I sometimes wonder whether people adopt Rust/Haskell/ReasonML for front-end work because they want it to feel like more of an effort than it otherwise would.
- staticassertion 5y agoMy company has its code basically split in half between Python and Rust. Our Python code uses mypy pretty aggressively. The iteration speed difference is... drastic. Rust far outshines Python in terms of our ability to get something done, maintain it, and iterate on it over time.
- muglug 5y agoThat's great for you and your team, but looking at https://github.com/grapl-security/grapl https://github.com/grapl-security/grapl it seems like your needs are pretty different from most web developers.
- staticassertion 5y agoHow so? We use many of the crates listed on the linked page - sqlx, rusoto, actix-web, tower/tonic, etc.
- muglug 5y agoYeah, but the thing you're building is quite a bit more complex than the average consumer-focussed website.
- pkrumins 5y agoRust is not a programming language it’s a syntax error.
- Snelius 5y ago
- nkim12 5y agothere is also fork of actix-web https://github.com/ntex-rs/ntex https://github.com/ntex-rs/ntex
- brundolf 5y agoI really want Rocket to take off (no pun intended), but it reached v0.5-rc nearly a year ago, and has yet to even bump up to v0.5 proper. It's hard to feel confidence that it has the wings to be the future of Rust web given its current rate of development, which makes it hard to justify using in a work setting. Does anybody have more insight into its development status?
- Sytten 5y agoThis website really needs an update. Many people mentionned Axum. On the DB side you should check out sea-query and sea-orm. Many negative rust comments over here. It sure did take me a few months to get comfortable with the language and its idioms, but man do I not want to go back to languages without a borrow checker now. The compiler and clippy is just so good at catching bugs. Give it a few years to mature the async/await (it is a mess currently no gonna lie) and it could displace Golang especially for cases where you care about tail latency.
- WaxedChewbacca 5y ago
- chmod600 5y agoDoes anyone else find it amazing how we are able to collectively rewrite entire ecosystems every time new language comes along? Web frameworks, network libraries, image libraries, parsers/serializers, etc.? And the second realization is that the idea of polyglot programming has utterly failed. A lot is due to what kinds of APIs can be exposed between components, and that seems like an inherent problem of communication between different languages. But there are other areas where you'd think we'd have wider agreement by now: the semantics of data types, runtimes, ABIs, memory layouts, etc. I guess there are lots of reasons for differences. But it's kinda sad how much effort is spent re-writing stuff that already exists and works in a different language.
- bluszcz 5y agoI love ironic tone of this post. In funny and twisted way author explained how poor rust for web is. Thanks for making us aware :)