Rust pointers for C programmers
When I was learning Rust I leaned heavily on C-based analogies like this but I found they ultimately ended up being kinda harmful, because I was thinking (in C mode) "do I want to pass a pointer or a value to this function" rather than (in Rust mode) "do I pass ownership or a borrow to this function".<p>For an example of the difference, here's a function that consumes a 1kb buffer, returning the sum some of its contents.  No pointers or references at all, everything "passed by value".<p><a href="https://godbolt.org/g/icoVvz" rel="nofollow">https://godbolt.org/g/icoVvz</a><p>To my C programmer's eye this looks wrong, but from the output you see there is no memcpy.  (Edit: this is wrong, both C and Rust do memcpy, see below comments, but I think my point stands.)<p>I'd be shocked to see a C programmer write the equivalent code ("passing by value a big struct to a function"), while in Rust it's not only idiomatic to write that code but frequently also necessary, depending on whether the function wants to take ownership its argument or some of its contents.  (Imagine a more complicated 'stuff' struct that contained embedded pointers to other things.)<p>I'm a little embarrassed to say I ended up looking at the output on rust.godbolt.org a lot to convince myself that the bits of code I was writing was "ok", which is something I never did when learning e.g. Haskell or Go.  I think the reason here is that Rust feels so close to C that there's a bit of an uncanny valley effect, where you can mostly pretend it's C up until you hit a wall.