Fuck me sideways, Rust is so hard. Will we ever be friends?
fn sub(foo: &String) {
println!("We got this string: [{}]", foo);
}
fn main() {
// "Hello", 0x00, 0x00, "!"
let buf: [u8; 8] = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x00, 0x21];
// Create a string from the byte array above, interpret as UTF-8, ignore decoding errors.
let lossy_unicode = String::from_utf8_lossy(&buf).to_string();
sub(&lossy_unicode);
}
Create a string from a byte array, but the result isn’t a string, it’s a cow 🐮, so you need another to_string() to convert your “string” into a string.
- https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf8_lossy
- https://doc.rust-lang.org/std/borrow/enum.Cow.html
I still have a lot to learn.
(into_owned() instead of to_string() also works and makes more sense to me, it’s just that the compiler suggested to_string() first, which led to this funny example.)
@lyse@lyse.isobeef.org Rust is so different and, at the same time, so complex – it’s not far fetched to assume that I simply don’t understand what’s going on here. The docs appear to be clear, but alas … is it a bugs in the docs? Is it a lack of experience on my part? Who knows.
By the way, looks like there was a bit of a discussion regarding that name:
So I was using this function in Rust:
https://doc.rust-lang.org/std/path/struct.Path.html#method.display
Note the little 1.0.0 in the top right corner, which means that this function has been “stable since Rust version 1.0.0”. We’re at 1.87 now, so we’re good.
Then I compiled my program on OpenBSD with Rust 1.86, i.e. just one version behind, but well ahead of 1.0.0.
The compiler said that I was using an unstable library feature.
Turns out, that function internally uses this:
https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.display
And that is only available since Rust 1.87.
How was I supposed to know this? 🤨
@prologic@twtxt.net Yeah, it’s difficult, you often don’t get what you’d expect. They also make heavy use of 3rd party libraries. IIUC, for random numbers, they refer to this library. I’ve read many times that the Rust stdlib is intentionally minimalistic (to make it easier to maintain and port and all that).
I’m struggling with this, using 3rd party libs for so many things isn’t really my cup of tea. I’ll probably make my own tiny little “standard library”. It’s silly, but I don’t see any other options. 🤷
@movq@www.uninformativ.de LOL 🤣 I don’t think I could ever take Rust seriaujly 🤦♂️
I wanted to port this to Rust as an excercise, but they still have no random number generator in the core library: https://github.com/rust-lang/rust/issues/130703
I Learned Rust In 24 Hours To Eat Free Pizza Morally
This is a satirical tech story. For readers who prefer the text version, it’s provided below.
I Learned Rust in 24 Hours to Eat Free Pizza Morally
This is not just a story about pizza. As a recent Phoronix article explains,
the Linux Rust subsystem got into major drama because of my humble quest.
Well, here’s my side of the story, with every kernel of truth exposed.
A Moral Quest for Pizza
Des … ⌘ Read more
Linux 6.15 released
Highlights of Linux 6.15 include Rust support for hrtimer and ARMv7, a new setcpuid= boot parameter for x86 CPUs, support for sched_ext to count and report internal events, x86 Intel and AMD PMU enhancements, nested virtualization support for VGICv3 on ARM, and support for emulating FEAT_PMUv3 on Apple Silicon. ↫ Marius Nestor at 9To5Linux On top of these highlights, there’s also a ton of other changes, from the usual additions of new drivers, to better support for RISC-V, and so much more … ⌘ Read more
@kat@yarn.girlonthemoon.xyz Ah, I see. I would assume that you’ll get used to it at some point. 🤔 But yeah, a lot of meaning is packed into these symbols. (It’s much, much worse with languages like Rust. 😅)
10 Ancient “Smart” Materials Scientists Still Can’t Reproduce
As civilizations from Rome to the Maya harnessed empirical ingenuity to create materials with built-in healing, color-shifting, or structural resilience, they left behind recipes that modern science is only now decoding. From rust-proof iron pillars and self-repairing concrete to nanotech-level glass and ancient vulcanized rubber, these ten remarkable “smart” materials demonstrate how our ancestors engineered […] … ⌘ Read more
Microsoft Creates MS-DOS EDIT.COM Clone in Rust
The classic DOS text editor has returned! ⌘ Read more
Google’s “AI” is convinced Solaris uses systemd
Who doesn’t love a bug bounty program? Fix some bugs, get some money – you scratch my back, I pay you for it. The CycloneDX Rust (Cargo) Plugin decided to run one, funded by the Bug Resilience Program run by the Sovereign Tech Fund. That is, until “AI” killed it. We received almost entirely AI slop reports that are irrelevant to our tool. It’s a library and most reporters didn’t even bother to read the rules or even look at what the intend … ⌘ Read more
Rust celebrates ten year anniversary with Rust 1.87.0 release
I generally don’t pay attention to the releases of programming languages unless they’re notable for some reason or another, and I think this one qualifies. Rust is celebrating its ten year anniversary with a brand new release, Rust 1.87.0. This release adds anonymous pipes to the standard library, inline assembly can now jump to labeled blocks in Rust code, and support for the i586 Windows target has been rem … ⌘ Read more