@andxor@mstdn.social cover
@andxor@mstdn.social avatar

andxor

@andxor@mstdn.social

I write code & dive underwater (not necessarily at the same time)

I’m a software developer from #Italy, currently living in #Seattle. Scuba driver in my spare time.

Interested in: #FreeSoftware #Ubuntu #Privacy #CloudComputing #Cryptography #Math #Scuba

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?

andxor ,
@andxor@mstdn.social avatar

@became_fish that would be a slice:

let s = "abc";
foo(&s[1..2]); // read-only slice

let mut s = String::from("abc");
bar(&mut s[1..2]); // read-write slice

andxor ,
@andxor@mstdn.social avatar

@became_fish yes, you use mutable references for that use cases. They're equivalent to non-const pointers in C++, with the exception that Rust references don't cause undefined behavior

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