Searching We.Love.Privacy.Club

Twts matching #rust
Sort by: Newest, Oldest, Most Relevant

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.

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.)

⤋ Read More
In-reply-to » So I was using this function in Rust:

@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:

https://github.com/rust-lang/rust/issues/120048

⤋ Read More

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? 🤨🫩

⤋ Read More
In-reply-to » 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

@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. 🤷

⤋ Read More

淺析 rust 大明星 Tokio
Tokio 可以說是 rust 中最熱門的庫,對於異步與併發進行了很好的支持。大多數基於 rust 的開源框架都使用到了 Tokio,因此在介紹這些實現開源框架時經常會被問到:底層的異步和併發是怎麼實現的?我只能回答:底層的異步和併發都是由 Tokio 控制的。這顯然不是一個令人滿意的回答。因此本文章將對於 Tokio 的基本方法和底層邏輯進行分析。概述一句話概括 Tokio 可以理解成一個 “ ⌘ Read more

⤋ Read More

深入 Biome — 現代 Rust 前端工具鏈
Biome 簡介Biome 是一個基於 Rust 開發的前端工具鏈工具,它提供了完善的 Analyzer / Linter / Formatter 的能力支持。目前 Biome 提供了 JS、TS 、JSON/JSONC 以及 CSS 和 GriftQL 等語言的支持。在 Linter 方面,目前 Biome 內置支持了約 320 條以上規則支持 (參考: https://next.biomejsRead more

⤋ Read More

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

⤋ 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

⤋ Read More
In-reply-to » i wish it was realistic for me to learn golang but every single time i try to comprehend any go code i'm like What the fuck am i looking at. why is all of this so short and condensed GIVE ME VERBOSE CODE

@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. 😅)

⤋ Read More

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

⤋ 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

⤋ Read More

tokio-mpmc:高性能異步多生產者多消費者隊列
tokio-mpmc 是一個基於 Tokio 異步運行時的高性能多生產者多消費者隊列實現,專爲異步 Rust 應用提供高效的數據傳遞機制。本文將深入淺出地介紹其架構設計、工作原理和使用方法。設計背景在異步編程中,特別是構建高性能併發系統時,任務間的數據傳遞是核心問題。雖然 Rust 生態中已有多種隊列實現(如 std::sync::mpsc、tokio::sync::mpsc、tokio::syn ⌘ Read more

⤋ Read More

Flutter 與 Rust 跨界聯手:打造跨平臺開發新紀元
使用 Rust 與 Flutter 的理由假設我們需要獲取當前設備的電池電量。如果沒有任何插件提供這種功能,那就必須解決兩個問題:如何在本地代碼和 Flutter 之間傳輸數據,以及如何處理不同平臺的特定語言(如 C++/Kotlin/Swift 等)。數據傳輸挑戰——在 Flutter 應用和本地代碼之間傳輸大量數據時,創建綁定以實現在兩者間的數據交換是必要的。這個過程涉及到大量的樣板代 ⌘ Read more

⤋ 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

⤋ Read More