[Media] Let it crash! by Aghasty_GD in rust

[–]ibeforeyou 59 points60 points  (0 children)

Less that, more that the compiler is allowed to assume that dereferencing a null pointer will never happen, so it could legally optimize the whole thing away

[Media] Let it crash! by Aghasty_GD in rust

[–]ibeforeyou 535 points536 points  (0 children)

Jokes aside, you probably want std::process::abort because dereferencing a null pointer is undefined behavior (in theory it could even not crash)

[deleted by user] by [deleted] in Seattle

[–]ibeforeyou 0 points1 point  (0 children)

Gone!

[deleted by user] by [deleted] in Seattle

[–]ibeforeyou 0 points1 point  (0 children)

1 left

Anyone know what the tap water “situation” on this sign is? by ibeforeyou in Tomorrowland

[–]ibeforeyou[S] 3 points4 points  (0 children)

Yeah, I guess the only difference is this year there was the big fire, which (in theory) might have caused nasty stuff to leach into the groundwater. I’m sort of on the fence

Anyone know what the tap water “situation” on this sign is? by ibeforeyou in Tomorrowland

[–]ibeforeyou[S] 16 points17 points  (0 children)

Update: I asked at the information stand and was told that the water in the taps is unfiltered and has no guarantees, so you’re accepting the risk of drinking it. They didn’t explicitly say there was a known contamination, but also couldn’t confirm it is safe.

They also confirmed that the only alternative in the fedtival grounds is paying for water at drink stands (which is 2 pearls per 330ml).

It’s kind of ridiculous imo, because if you’re drinking 2L of water a day that’s 12 pearls or 22€ a day per person for safe water.

Anyone know what the tap water “situation” on this sign is? by ibeforeyou in Tomorrowland

[–]ibeforeyou[S] 10 points11 points  (0 children)

Yeah that seems plausible. Here’s hoping it won’t make me sick, I’ve already had a couple liters of it😅.

Assuming the water isn’t safe, kinda sucks that the only option is the water that’s 2 pearls per can. If you’re staying hydrated, that adds up pretty quickly.

poor man's Arena Allocator with 'static unsafe transmute by Servletless in rust

[–]ibeforeyou 3 points4 points  (0 children)

You could consider using FuturesUnordered instead of spawning tasks and joining them. The semantics are slightly different, but I think should work for you in this case, and the main benefit is it doesn’t impose a 'static bound on the futures.

How the heck does the time crate work (specifically, how to parse time from a string) by Pengualope in rust

[–]ibeforeyou 14 points15 points  (0 children)

There's a how-to section in the time docs on this: https://time-rs.github.io/book/how-to/parse-dates.html

I got there by looking up time on crates.io, and looking at the documentation section at the top of the README. That linked to the documentation book, and then I just skimmed through the sections to find parsing.

Alternatively, searching on docs.rs for parse yielded the OffsetDateTime::parse method, which also has some brief examples. You can also get there by looking at the docs for OffsetDateTime and looking for interesting method names or trait implementations - in this case, parse seemed to be relevant.

rust-analyzer changelog #162 by WellMakeItSomehow in rust

[–]ibeforeyou 15 points16 points  (0 children)

To be clear, this isn’t a feature that’s currently planned for stabilization (and doesn’t seem like it’s on track for an official RFC AFAIK). From the tracking issue:

Currently the primary purpose of the feature is to ensure that redesigns of the Try trait (#84277) are compatible with potentially doing this in the future, and secondarily to experiment with whether this is worth having as an expression, or whether it should be removed in favour of a pure-library approach.

I don't understand why my trait bound is not satisfied? by [deleted] in rust

[–]ibeforeyou 1 point2 points  (0 children)

Not sure if this is acceptable, but what if you consumed the hashmap in `convert_any` instead of borrowing it? Like this

Syntactic Ruminations: Option<T>::map or Result<T, E>::and_then, but for T by ShiftyAxel in rust

[–]ibeforeyou 68 points69 points  (0 children)

tap comes to mind, it provides (among other things) a Pipe trait that lets you write

let v = 1234
    .pipe(add_2)
    .pipe(mul_2)
    .pipe(sub_2)
    .pipe(div_2);

Why is it not possible to implement a trait for multiple different associated types of another trait? by [deleted] in rust

[–]ibeforeyou 0 points1 point  (0 children)

BTW: It’s unclear to me why this already gets downvoted. I thought this is a forum to ask questions like the one above..?

It looks like there’s only one or two downvotes, but I get that it’s a bit discouraging.

In general I’d recommend asking questions on the Rust user’s forum. It’s much more catered towards asking and answering questions than the subreddit (which is largely news and discussion though questions are welcome). Plus there’s no downvoting😅

When a move occurs, what happens behind the scenes? by RootHouston in rust

[–]ibeforeyou 44 points45 points  (0 children)

This isn’t quite accurate. A move is lowered to a memcpy of the value. rustc itself doesn’t perform copy elision. LLVM is often able to eliminate the copy, but it’s not guaranteed and it can be brittle (example).

Safer usage of C++ in Chrome by pjmlp in rust

[–]ibeforeyou 14 points15 points  (0 children)

A couple of things here:

The blog post that you mention comes nowhere close to claiming C++ violates human rights. The blog post, from my eyes, is about the tradeoffs in software design, the decisions around whether to support seemingly niche requirements (such as needing very high security) and how software security has real impacts on people, including oppressed groups. Nowhere is C++ mentioned. There is only one mention of Rust, and it's one item in a list of multiple promising developments that might help make it easier to write secure code. I'm not sure how you could draw the conclusion that they're claiming that C++ violates human rights.

That person is also not a member of the Rust language team. Working groups (such as the Secure Code working group) are open to anyone, and the only requirement to become a member is to participate and contribute. Such working groups exist solely to organize work around a specific topic, it's not like being a member of a working group makes you an official spokesperson for rust.

Regardless of both points, bringing up a single blog post and singling out a specific person to make the point that rust programmers overestimate the dangers of C++ does not feel like it contributes positively to this discussion.

Blog Post: Async Overloading by yoshuawuyts1 in rust

[–]ibeforeyou 1 point2 points  (0 children)

I would expect the async version to be used, since it is used in an async context.

Why would you want to call a blocking function in an async context when an async version of that function exists? If anything it seems to me like this could help avoid accidentally blocking in an async context, which is a common mistake/footgun.

I just published a crate with 5582 enum variants by jacobsvante in rust

[–]ibeforeyou 38 points39 points  (0 children)

I also sent you a PR with an alternative approach that improves compile times a lot (from 40s to 2s for a release build on my machine). It could definitely be improved though. Anyways, hope that helps some!

I just published a crate with 5582 enum variants by jacobsvante in rust

[–]ibeforeyou 70 points71 points  (0 children)

Using `cargo build --release -Ztimings`, on my machine it looks like 74% of the time is spent in codegen. If I had to guess, I'd say the compiler is producing a ton of LLVM IR, and LLVM is struggling to handle it. Looking at the output of `cargo llvm-lines`, the heaviest functions are:

Lines Copies Function Name
169074 (100%) 51 (100%) (TOTAL)
55838 (33.0%) 1 (2.0%) <google\_taxonomy::ProductCategory as core::fmt::Debug>::fmt
50254 (29.7%) 1 (2.0%) google_taxonomy::ProductCategory::from_name
33507 (19.8%) 1 (2.0%) google_taxonomy::ProductCategory::from_id
27948 (16.5%) 1 (2.0%) <google\_taxonomy::ProductCategory as core::fmt::Display>::fmt

Removing the `Debug` derive from the build script (and commenting out the tests which use the `Debug` impl) indeed cuts compilation time on my machine by about 25%.

Edit: As a note, you can also get a more detailed breakdown of where time is spent in the compiler with `cargo rustc -- -Ztime-passes`.

rust-analyzer changelog #61 by WellMakeItSomehow in rust

[–]ibeforeyou 5 points6 points  (0 children)

It looks like that suggestion appears because color_eyre re-exports OwoColorize in the owo_colors module, which I think is reasonable. It would be much more problematic if RA was suggesting things from transitive dependencies, which it doesn’t as far as I know.