Rust Programming

fzz , in Untwine - the pattern-matching parsing library capable of a 12 line JSON parser with pretty errors
@fzz@programming.dev avatar

Looking to example code in the README I have to say that it is neat! ❤️‍🔥
But know what? Could be awesome to support char-literals in the parser! macro. Currently in that example str-literals used as single-char strings.
I mean this for example:

num: num=<"-"? '0'-'9'+ …

Why there dash is str but not a char?
Also what about escapes, unicode sequences and binary literals?

redempt OP ,

There's no real need for character literals. They would behave exactly the same as string literals but only support a single character. And you can use escape sequences in the string literal, of course.

fzz , (edited ) in Ferris and Corro wallpaper
@fzz@programming.dev avatar

I suppose there should be something like Crang (“friend” of Shredder) without exoskeleton and covered with spikes, like your Corro.

QaspR OP ,

If this is a reference, it's lost on me 😂

fzz , (edited )
@fzz@programming.dev avatar

this or this.

QaspR OP ,

Well that clears it up

Deebster ,
@Deebster@programming.dev avatar

He's a baddie from Teenage Mutant Ninja Turtles

calcopiritus , in Announcing Rust 1.79.0 | Rust Blog

The lifetime extension is huge.

tmpod OP ,
@tmpod@lemmy.pt avatar

Indeed!

Ephera , in Announcing Rust 1.79.0 | Rust Blog

I only really understand half of it without getting my fingers on it, but sounds like some good stuff.

The path::absolute() that's hidden in the stabilized items is definitely something I've wanted for a while, though.

tmpod OP ,
@tmpod@lemmy.pt avatar

The two biggest things are lifetime extensions and inline consts. Both will allow you to write more concise code and, in the case of lifetime extensions, may help eliminate some bugs, since you won't need to work around that limitation anymore.

Ephera ,

Yeah, I'm imagining, I've run into these problems in the past and then the compiler told me to do it differently and so I did. I'm definitely glad that such unobvious behavior is being reduced, I just probably won't realize until I'm writing similar code the next time and the compiler does not complain.

tmpod OP ,
@tmpod@lemmy.pt avatar

Yeah exactly! It's a great case of "invisible" improvements.

TehPers ,

Inline consts also let you perform static assertions, like asserting a type parameter is not a zero-sized type, or a const generic is non-zero. This is actually pretty huge since some checks can be moved from runtime to compile time (not a lot of checks, but some that were difficult or impossible to do at compile time before).

Killing_Spark ,

I'm not really sure I get the usefulness of this absolute function. It still returns relative paths if the input was relative and it doesn't resolve "..". What would you use it for where canonicalize doesn't work for you?

Ephera ,

Well, as it says in the documentation I linked:

unlike canonicalize absolute does not resolve symlinks and may succeed even if the path does not exist.

Primarily, the latter part is what I want. There's just sometimes situations where a path doesn't exist (yet), but you want to know what it would look like as an absolute path.

taladar , (edited )

In 99% of those cases you would want it to resolve .. components though.

ssokolow ,
@ssokolow@lemmy.ml avatar

It still returns relative paths if the input was relative

False

and it doesn’t resolve “…”

I'll assume you meant .., since ... is an ordinary filename. (Aside from the "who remembers ...?" feature introduced in Windows 95's COMMAND.COM where cd ... was shorthand for doing cd .. twice and you could omit the space after cd if your target was all dots.)

The reason it doesn't do that is that, when symlinks get involved, /foo/bar/.. does not necessarily resolve to /foo and making that assumption could introduce a lurking security vulnerability in programs which use it.

Killing_Spark ,

Hm it seems I misread the documentation there. I know why it doesn't resolve the ".." and that's fine, it just seemed very unnecessary in combination with my flawed understanding of the relative path handling.

Edit: and just to be snarky: I didn't type "..." I typed "..". ;)

ssokolow ,
@ssokolow@lemmy.ml avatar

Edit: and just to be snarky: I didn’t type “…” I typed “…”. ;)

*chuckle* I think Lemmy typed those for you, because I typed three periods and got a Unicode ellipsis, and both of those are also unicode ellipses.

Killing_Spark ,

Huh that might actually be an issue with your client, mine renders those as two dots

ssokolow ,
@ssokolow@lemmy.ml avatar

I'm using the web UI, so I'm assuming whatever broad-spectrum Markdown rendering library it uses has smart quote rendering turned on.

krnpnk , in Announcing the Safety-Critical Rust Consortium

I've been waiting for something like that for quite a while. Let's hope it really drives forward adoption in safety critical software 🙂

BB_C , in [SOLVED] Is there a way to start and stop chromedriver/geckodriver with Rust and Selenium (thirtyfour) automatically like in Python?

I have no specific knowledge of this stuff. But the generic answer is an obvious one.
However Python code does it can be replicated in Rust.
For example, if python code executes the driver as a subprocess, then that too can be done in Rust.
So checking how Python code does it will probably lead to an answer to this question.

BB_C , in Stylelint alternative in rust?

Maybe ask a web dev community about this.
There could be something better written in Rust.
There could be something better NOT written in Rust.
They should know.

jamygolden OP ,

Thanks good idea, I’ll try asking there.

ssokolow , in [SOLVED] Rust-analyzer only somewhat working?
@ssokolow@lemmy.ml avatar

That's not how it's supposed to be.

but for example Vec::new() doesn’t highlight anything at all.

If I do Vec::new(foo, bar), I get expected 0 arguments, found 2 (rust-analyzer E0107).

but things like passing too many arguments into the println macro doesn’t throw an error.

I don't get that either, but I'm still running with the Vim configuration I setup on my previous PC from 2011, where I turned off checks that require calling cargo check or cargo clippy in the background. From what I remember, a properly functioning default rust-analyzer config should pick up and display anything cargo check will catch and you can switch it to cargo clippy for even stricter results.

Or how shown in this example, it did not autocomplete the clone method, while also just accepting .clo; at the end of a String (it also didn’t autocomplete “String”).

I get clone(), clone_into(), and clone_from() as proposed completions for .clo on my as-you-type completions for foo where let foo = String::new(); and it proposed a whole bunch of things, with String at the top when I typed Stri. (eg. the stringify! macro, OsString, mixed in with various results from other crates in the project like serde)

Smorty OP ,

Turns out, the *.rs file needs to be in some kind of folder structure, like the one provided by cargo when creating a project. I was just editing the loose files in the rustlings program, and because they are not in a proper program folder structure, most of the syntax stuff didn't show up.

Thank you for sharing your experience though! It was very useful for figuring out if what I had was an issue or normal behavior. Now my neovim works perfectly with all the syntax highlighting I could wish for.

ssokolow ,
@ssokolow@lemmy.ml avatar

Ahh, yeah. In the beginning, Rust was built around the idea that individual files and invoking rustc are internal details, only relevant for integration into some other build system like Bazel, and that "normal" Rust projects need to be inside a Cargo project structure.

There is in-development work to have official support for something along the lines of rust-script, but it's still just that... in development. If you want to keep an eye on it, here is the tracking issue.

BB_C , in Faster linking times on Linux using `rust-lld`

Good. But a lot of us do this already:

[target.x86_64-unknown-linux-gnu]
linker = "clang" # for mold
rustflags = ["-c", "link-arg=-fuse-ld=/usr/bin/mold"]

[target.x86_64-unknown-linux-musl]
rustflags = ["-Z", "gcc-ld=lld"]
mrfoxh , in React Compiler has been open sourced, and, it's written in Rust
@mrfoxh@ruby.social avatar

@vit I use , and .
I don't like .

ssokolow ,
@ssokolow@lemmy.ml avatar

...and I could just as easily disparage those frameworks and give concrete reasons, but I don't. If you don't have something constructive to say, please be courteous and say nothing.

mrfoxh ,
@mrfoxh@ruby.social avatar

@ssokolow is that constructive? :honeybadger:

beeb ,
@beeb@hachyderm.io avatar

@ssokolow @mrfoxh what the hell is that reasoning? If you don't care for their opinion just go your merry way lol

ssokolow ,
@ssokolow@lemmy.ml avatar

Signal to noise ratio.

Aside from possibly making them feel better, it doesn't benefit anyone for them to drop into a topic about thing X and say nothing but "I use thing Y. I don't like thing X." and it wastes other people's time either scrolling past it or clearing out their RSS reader, depending on how they follow things.

beeb ,
@beeb@hachyderm.io avatar

@ssokolow rather than snarkily point out that the comment was not substantiated and dismissing it, you could also simply politely ask for clarification. "What is an aspect of React you don't like?"

mrfoxh ,
@mrfoxh@ruby.social avatar

@beeb @ssokolow exactly 👍

ssokolow ,
@ssokolow@lemmy.ml avatar

Fair. That would have been more constructive... I think I didn't do that because it still would have felt like encouraging off-topicness.

ignotum , in Early pest3 prototype was released on crates.io

Awesome! I've been tinkering with a project where i needed semi-advanced text parsing, and my homebrew solution is a barely functional mess, this looks perfect!

ssokolow ,
@ssokolow@lemmy.ml avatar

Depending on your preferences, there's also Nom if you prefer parser combinators, or lalrpop or grmtools if you prefer LR(1) parsing.

Since reading Which Parsing Approach by Laurence Tratt (author of grmtools), my plan for my own parsing projects has been to use an LR(1) parser generator for the stronger compile-time guarantees.

Narann , in Microsoft's $1M Vote of Confidence in Rust's Future
@Narann@lemmy.world avatar

Am I the only one having some concerns about a technology which organisation is going too widely high profit company dependent?

BB_C ,

I didn't understand your sentence. But:
Having concerns is valid.
Having them in the context of this story/ad is misplaced.

IBM invested 1B$ in Linux all the way back in year 2000 (imagine how much that is worth with tech inflation), and they did it again years later.

That 1M$ is nothing. It's not nearly enough to control the Rust foundation for one year, let alone controlling the Rust project as a whole. Calling it a "Vote of Confidence in Rust's Future" was probably a good-spirited joke from the author, at least I hope it was.

Note that IBM still doesn't control Linux (even after acquiring RedHat), and we still have no problem calling them evil. Some of us still have no problem calling MS evil either, although many of the new crop of developers won't, because for them the chance to have the financial privilege of working there someday outweighs any moral considerations. Incidentally, there is a good intersection between this group, and the group that takes moral posturing about whatever in-group approved cause of the month to the maximum. Ironic, isn't it?

homesweethomeMrL , in Microsoft's $1M Vote of Confidence in Rust's Future

If microsoft made 22 billion of profit in three months, that’s 88 billion a year, so they donated 0.001% to rust.

But hey, a million bucks is a million bucks.

danc4498 ,

Right. That's $1 million less in taxes

anlumo ,

Only if they have a 100% tax rate, which I doubt.

BB_C ,

This is effective advertisement, not a donation. A real ad (with a campaign) would probably have cost much more, and wouldn't continue to be propagated for free months after the ad campaign is over, like this peace of news.

This type of ad is also much harder to filter/block, since not only it appears to be site-native, but also topic-native.

toastal ,

Just like the random Sponsor drop to get more folks enrolled in their donation system so they can skim more off the top of the transaction.

Trafficone , in Rusty Playdate - Toolset and API

This is great. I totally bounced off of crank/crankstart, but I think I understand this toolchain better

grapemix , in Rusty Playdate - Toolset and API

Why not? ;)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • rust@lemmy.ml
  • test
  • worldmews
  • mews
  • All magazines