Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Defeatist Elitist
Jun 17, 2012

I've got a carbon fixation.

Are there any particular extensions or settings that make a huge difference for the user experience when setting VS Code up for Rust (other than rust analyzer of course)?

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=
Make sure you're running clippy. I feel like the only other setting I have to tell juniors to use is to trim trailing whitespace and add a trailing newline, neither of which is rust specific. Gone are the days where there was a huge trap with RLS/RA.

Defeatist Elitist
Jun 17, 2012

I've got a carbon fixation.

gonadic io posted:

Make sure you're running clippy. I feel like the only other setting I have to tell juniors to use is to trim trailing whitespace and add a trailing newline, neither of which is rust specific. Gone are the days where there was a huge trap with RLS/RA.

Awesome, yeah, thanks, that was exactly the type of thing I was looking for.

gonadic io
Feb 16, 2011

>>=
oh and rustfmt too

Defeatist Elitist
Jun 17, 2012

I've got a carbon fixation.

gonadic io posted:

oh and rustfmt too

I believe the default behavior of rust-analyzer is to use rustfmt, but it's possible you mean something else and I am not understanding.

gonadic io
Feb 16, 2011

>>=
If it already is then great, but I seem to remember it is a vscode setting to specifically use rustfmt.

Defeatist Elitist
Jun 17, 2012

I've got a carbon fixation.

gonadic io posted:

If it already is then great, but I seem to remember it is a vscode setting to specifically use rustfmt.

Yeah, looks like it has been included but there were some other formatting settings that I had forgotten to change on my new computer so I'm glad I checked. Thanks again.

Ihmemies
Oct 6, 2012

So has the time of Rust enjoyers finally come? :bederper:

Consumer reports advocates memory-safe languages like Rust, instead of legacy languages like C/C++:
https://advocacy.consumerreports.org/research/report-future-of-memory-safety/
So does NSA: https://www.nsa.gov/Press-Room/News...-safety-issues/
Noticeable parts of Windows have already been rewritten in Rust: https://www.theregister.com/2023/04/27/microsoft_windows_rust/
Apparently Rust was accepted as an language for linux kernel development etc.

Our School still teaches C++ and ANSI C (ugh :shepicide:). No rust courses. I didn't get any job for summer, so I guess it's time to learn rust? :v:
Someone said this is more comperehensive: https://doc.rust-lang.org/stable/book/ than this: https://doc.rust-lang.org/rust-by-example/

Any pro tips on which to use? I guess Vscode is an ok editor for Rust, if I configure it as you suggested earlier in the thread.

gonadic io
Feb 16, 2011

>>=
Vscode is certainly fine, I personally prefer jetbrains.

From the perspective of learning, and I've taught several different colleagues from scratch, I feel like the knowledge you need for rust is basically half C++ half Haskell.

I (and some of those coworkers) knew the latter but not the former, and traits and rich enums and so on all came easily to me but things like borrowing and ownership were a steep learning curve.

For the ones who knew C++ but not Haskell, it was mostly the opposite. Borrowing is more or less textbook C++ RAII rules from my understanding but more restrictive in that even "safe" multiple mutable borrowing can't be verified by the compiler so you have to jump though some hoops to do so but I would really recommend trying not to and trying to get used to doing things the more rust idiomatic way.

E: also fight the urge you'll have from cpp macros to use macros in place of all tiny functions to guarantee inlining

gonadic io fucked around with this message at 13:40 on Apr 30, 2023

VikingofRock
Aug 24, 2008




gonadic io posted:

From the perspective of learning, and I've taught several different colleagues from scratch, I feel like the knowledge you need for rust is basically half C++ half Haskell.

This is very accurate I think. My Rust story is that around 2015 (or so?) I was writing C++ for work and Haskell for fun, and was pining for a C++ that took some of the nicer ideas from Haskell and which had better defaults. I googled around a bit to see if such a thing existed and found the Rust beta.

kujeger
Feb 19, 2004

OH YES HA HA
Seconding the C(++) and Haskell thing; I did a bit of C as a kid and a little Haskell more recently (plus python and perl at work) and found getting into Rust relatively easy and enjoyable, even switching from being a sysadmin to developer full time at roughly the same time. But I've also kept an eye on rust for years, never using it for anything "real" or at work until the last two years or so.

The Java/Kotlin folks at work who've gotten into it had a bit more of a struggle having to think about memory as a thing at all, but now like it a lot.

VSCode plus rust analyzer works very well for me.

repugnant
Jun 29, 2005

You can only think of me.

I was thinking of learning Rust by doing a simple (I hope) embedded GUI with Rust and either Slint or LVGL rust bindings. Rust seems to be a first-class citizen for Slint, but LVGL seems pretty good too. I'm coming from a C++/Qt background, and the virtual keyboard examples in Rust versus C++ make Rust look really verbose. https://github.com/slint-ui/slint/tree/master/examples/virtual_keyboard. I'm making y way through the Rust book so hopefully it'll make more sense when I'm finished.

Has anyone here done a GUI in Rust yet?

kujeger
Feb 19, 2004

OH YES HA HA
I've done a little with Iced, which worked well enough. Am curious about trying slint as well.

It looks like Iced is more focused on giving native looks, while slint is more for custom stuff.

e: oh yeah embedded, i don't think iced is going to work there

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.
Anyone tried out copilot with Rust?

My experience in other languages has generally been that can recognize semi-repeating patterns within a project and that it can helpfully complete a lot of boilerplate.

I would imagine that it can do helpful-but-tedious-to-write stuff (e.g. a full set of arithmetic overrides for types that are like vectors or grids) and might make the occasional good suggestion of how to use stdlib bits and bobs.

crazypenguin
Mar 9, 2005
nothing witty here, move along
I haven't.

At the risk of going wildly off topic, I'm really uninterested in any of the generative crap.

But I am very excited about the possibilities for LLMs in creating ultra-specific search engines. I wasted 4 hours once trying to find the function in the 'petgraph' library for computing a strongly connected component graph. I knew it had to be there, but in the end I had to give up on the docs and clone the repo and grep. (The function is called 'condensation' apparently?? And no search for 'scc' or 'component' will find it in the docs!%&$)

Domain-specific searching seems like a real potential killer app for these things. Let me search my dependencies with a spoken voice query in an IDE, that'd rule.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Copilot does a pretty good job with Rust, and the compiler helps you figure out where it went wrong. Code autocomplete or inter-language translation are really in the sweet spot for language models.

repugnant
Jun 29, 2005

You can only think of me.

I was going to start through the rust book again, and there's apparently an experimental, interactive version at https://rust-book.cs.brown.edu/experiment-intro.html, which has quizzes and visualizations as you go along. I'm going to try it out because I last went through the rust book a year ago and then never did anything with rust.

street doc
Feb 20, 2019

I want to take an image, split it, send it to 16 threads to process, send results from that to 4 threads to process and then repeat all over again.

Rayon? Tokio? Seems like arrays are fastest, but pretty loving hard to share/message.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

street doc posted:

I want to take an image, split it, send it to 16 threads to process, send results from that to 4 threads to process and then repeat all over again.

Rayon? Tokio? Seems like arrays are fastest, but pretty loving hard to share/message.

split_at_mut to get disjoint slices from your Vec of pixel data, use Rayon to chug through them. Or just copy the data into separate Vecs, some linear copies won't even register on your performance if the task is big enough to bother parallelizing. Tokio is not designed for CPU bound work.

street doc
Feb 20, 2019

Ralith posted:

split_at_mut to get disjoint slices from your Vec of pixel data, use Rayon to chug through them. Or just copy the data into separate Vecs, some linear copies won't even register on your performance if the task is big enough to bother parallelizing. Tokio is not designed for CPU bound work.

I was trying to stick to arrays and stay on the stack. Not really an option?

VikingofRock
Aug 24, 2008




street doc posted:

I want to take an image, split it, send it to 16 threads to process, send results from that to 4 threads to process and then repeat all over again.

Rayon? Tokio? Seems like arrays are fastest, but pretty loving hard to share/message.

Rayon is definitely what you want here. The result might not even be that different from the single-threaded code.

E: if it works for your use case, I'd probably first just try doing something like image.par_chunks(image.size() / 16).reduce(empty_processed_chunk, combine_processed_chunks). Let rayon figure out the number of threads to use.

VikingofRock fucked around with this message at 05:46 on May 10, 2023

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

street doc posted:

I was trying to stick to arrays and stay on the stack. Not really an option?

Stuff on the stack must be fixed size. Images are usually not. Really big arrays are not very efficient to manipulate by value anyway

gonadic io
Feb 16, 2011

>>=
Yeah if it's small chances are parallelising it is a net slowdown anyway unless it's some hugely expensive operation. If it's big it'll blow the stack anyway.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Are there any magic moonbeams that would get me library bindings for a Rust project that can be used with C, Python, and .NET? I think we can muster C and Python at least through some extra stuff but I wonder about .NET too. It's a reach but I thought I'd ask.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

you mean generate the PInvoke bridging for the exported C interface? your best bet there might be to generate them using a tool that consumes the generated C bindings, though you won’t get nice bundling in objects and so forth

there are not very many actually-good generated binding systems in the world, so moderating your expectations might be key to success here

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Well it looks like I don't even need .NET bindings after all, so I got lucky there.

prom candy
Dec 16, 2005

Only I may dance
Is there a reason there's no like Rust on Rails or Laravel equivalent or whatever. Like a batteries-included Rust web framework? I've been reading through the Rust book and everything about the language is so appealing to me but it seems like lots of people think it would be nuts to use Rust for that kind of higher level web programming. I guess I don't understand why because coming from the Ruby on Rails world I would love to have a rigid type system, Result types, and extremely good performance. Is it just because the community and ecosystem isn't there or does the day-to-day of working with Rust make it unsuitable for that type of work?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

I think Pavex is trying to head that way, with ergonomic metaprogramming and such?

crazypenguin
Mar 9, 2005
nothing witty here, move along

prom candy posted:

Is there a reason there's no like Rust on Rails or Laravel equivalent or whatever. Like a batteries-included Rust web framework? I've been reading through the Rust book and everything about the language is so appealing to me but it seems like lots of people think it would be nuts to use Rust for that kind of higher level web programming. I guess I don't understand why because coming from the Ruby on Rails world I would love to have a rigid type system, Result types, and extremely good performance. Is it just because the community and ecosystem isn't there or does the day-to-day of working with Rust make it unsuitable for that type of work?

I believe Rust generally, because of the narrative that it's a systems language comparable to C++, is currently generally used for more back-end stuff. Consequently, the library ecosystem there is much more mature (e.g. axum).

So for more app frameworky stuff, I think we're just waiting on (1) the library ecosystem to march in that direction over time and (2) to some extent, some of the ergonomic problems with async to be more fully resolved.

e: I also just want to say I agree with your impression, and I don't think there's anything (major) that makes Rust unsuitable. I think these frameworks will come.

crazypenguin fucked around with this message at 18:43 on May 25, 2023

gonadic io
Feb 16, 2011

>>=
All rust needs to be web ready is to make Arc<String> implement Copy :colbert:

prom candy
Dec 16, 2005

Only I may dance

Subjunctive posted:

I think Pavex is trying to head that way, with ergonomic metaprogramming and such?

I don't really want metaprogramming so much as a strong set of opinionated defaults. If you look at Laravel for example there are OOTB examples for most of the typical things you want to solve when you're creating web apps: routing, database migrations, authentication, authorization, queuing, scheduling, view templating, integration with front-end systems, serverless and serverful deployment, integration with payment processing systems, etc. Rather than having to reinvent the wheel or pick from 3-5 half-baked and possibly abandoned community solutions for each thing most of the common problems are just covered out of the box so you can get straight into building your product's specific features. But it's PHP.

Ranzear
Jul 25, 2013

prom candy posted:

[...]most of the common problems are just covered out of the box so you can get straight into building your product's specific features. But it's PHP.

Don't forget that Rust is eight years old, and PHP is twenty-eight years old.

prom candy
Dec 16, 2005

Only I may dance

Ranzear posted:

Don't forget that Rust is eight years old, and PHP is twenty-eight years old.

Yeah I was going to mention Laravel itself is turning 12 next month and Rails is god knows how old.

I've never done systems programming or worked with C/C++ so there are definitely topics in the Rust book that are new to me but even when making little toy command line apps I just can't stop thinking how nice it would be to have Rust's features even in higher-level contexts. Hell earlier today I was working on a React component and thinking about No Boilerplate's whole thing about "make unrepresentable states impossible" and how a Rust enum would've made what I was trying to do much simpler and enforce correctness at the same time.

gonadic io
Feb 16, 2011

>>=
That's the biggest downside of rust. Getting used to ADTs (i.e. enums with contents) and pattern matching just ruins you for going back to langs without it. An if-else chain of isInstanceOf just isn't the same...

necrotic
Aug 2, 2005
I owe my brother big time for this!

prom candy posted:

Yeah I was going to mention Laravel itself is turning 12 next month and Rails is god knows how old.

I've never done systems programming or worked with C/C++ so there are definitely topics in the Rust book that are new to me but even when making little toy command line apps I just can't stop thinking how nice it would be to have Rust's features even in higher-level contexts. Hell earlier today I was working on a React component and thinking about No Boilerplate's whole thing about "make unrepresentable states impossible" and how a Rust enum would've made what I was trying to do much simpler and enforce correctness at the same time.

This doesn’t help with your main ask (rust on rails stuff), but if you aren’t using typescript check it out. There are ways to fully type your state and everything else.

The enums aren’t the same as rust, but union types fill the role of enums with values.

prom candy
Dec 16, 2005

Only I may dance

necrotic posted:

This doesn’t help with your main ask (rust on rails stuff), but if you aren’t using typescript check it out. There are ways to fully type your state and everything else.

The enums aren’t the same as rust, but union types fill the role of enums with values.

I am using Typescript, it was the language that initially made me realize that compilers can tell me when I'm being an idiot and it made me completely fall out of love with Ruby.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Great! I kind of thought you would be given you posted in here, but the enum thing made me question so I commented.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

prom candy posted:

I am using Typescript, it was the language that initially made me realize that compilers can tell me when I'm being an idiot and it made me completely fall out of love with Ruby.

But, but…Sorbet!

:smith:

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
The Result and Option and match and enum are so good. Everyone talks about the speed and memory management, but for me it’s all about those algebraic data types.

I had to build an SDK in Go a couple weeks ago, and on one hand I like that it doesn’t have null values, but where was my Option?

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance

necrotic posted:

Great! I kind of thought you would be given you posted in here, but the enum thing made me question so I commented.

Yeah I think I probably will go back to that component and try to get the types a bit tighter but Typescript is a fair bit looser than rust. Also it has some issues like inferring arrayOfNumbers[0] as number instead of number | null.

Subjunctive posted:

But, but…Sorbet!

:smith:

I was hopeful but there's like no typing in the community and it also doesn't feel very good to use. Maybe this'll be the year Crystal finally takes off?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply