@nanobot248@mtd.sysblog.at avatar

nanobot248

@nanobot248@mtd.sysblog.at

🗣️🇩🇪, 🇦🇹, 🇬🇧, 🇺🇸, multiple programming languages and some 🏳️‍🌈
🏠 in Vienna (AT)

working with Java, JS, TS, HTML, CSS, Linux, nodejs, ...

Rust for leisure 🤩😍

C++ 😷 (even psychopaths have less undefined/unexpected behaviour)
C 🫣

"IT security is impossible for reasonably complicated computer systems."

  • Kurt Gödel, Alan Turing

This profile is from a federated server and may be incomplete. For a complete list of posts, browse on the original instance.

became_fish , to random
@became_fish@jorts.horse avatar

people say "C++ isn't any closer to the metal than is" but what is the memory footprint of returning a Result? in C++ i can pass an out parameter by reference to avoid allocating anything on the stack - how do i do that in rust? is it with a &mut ptr? is it done automatically by the compiler when returning?

nanobot248 ,
@nanobot248@mtd.sysblog.at avatar

@became_fish in Rust, a Vec<char> is not a string, so you can't create a string_view aka &str from it. you could create a &[char] slice (via as_slice()) from it. char is more or less equivalent to u32, so Vec<char> is like Vec<u32>.

an std::String is like a utf-8 encoded Vec<u8>. so from that you can create a &[u8] with as_slice() or a &str with as_str().

if you have Vec<char> and want &str, a conversion step (e.g. copy to String) is necessary, as the whole encoding/mem-layout is different.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • test
  • worldmews
  • mews
  • All magazines