# Hands-on Rust: Chapter 7 Invalid Camera Method from Chapter 5

**URL:** <https://forum.devtalk.com/t/hands-on-rust-chapter-7-invalid-camera-method-from-chapter-5/4282>\
**Category:** PragProg Customers\
**Tags:** book-hands-on-rust, errata\
**Created:** [22 November 2020 05:14 UTC](https://forum.devtalk.com/t/hands-on-rust-chapter-7-invalid-camera-method-from-chapter-5/4282 "2020-11-22T05:14:52Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![herbert](https://forum.devtalk.com/user_avatar/forum.devtalk.com/herbert/32/1233_2.png) [@herbert](https://forum.devtalk.com/u/herbert)\
**Post date:** [22 November 2020 15:40 UTC](https://forum.devtalk.com/t/hands-on-rust-chapter-7-invalid-camera-method-from-chapter-5/4282/2 "2020-11-22T15:40:10Z")

</div>

Thanks for finding that - great catch! I’m working on clearing that one up now, so it should make beta 2. It looks like an error slipped in when I merged some code branches on my machine (the bundled source compiles because the `on_player_move` signature changed without being mentioned in the text).

It’ll work either way, so long as the function is either `&Point` or `Point` and the calling code follows the same convention. The _correct_ form is just `Point`. The reasoning behind this is a little complicated (more so than I can justify adding into a beginner’s book), so I’ll try and explain it.

The `Point` structure ([source](https://github.com/thebracket/bracket-lib/blob/master/bracket-geometry/src/point.rs)) has a few properties:

- It’s internal representation is two `i32`, 32-bit signed integers.
- It derives `Copy` to make it “trivially copyable”.
- It implements all manner of niceties to work with other libraries and use a crate named `Ultraviolet` under the hood for fast SIMD math when you use it as a (math-style) vector.

Since the type is two 32-bit integers, its memory representation is 64-bits long. That’s really helpful, because on 64-bit architectures (most PCs these days) it fits into a single register. Copying it to a function becomes a VERY fast operation - place it in a register and off it goes. Even without a register, copying a single 64-bit value is a ridiculously fast `memcpy` operation under the hood. The fun part is that sending a reference is actually _slower_ in this case! References are really pointers under the hood. So the system sends a pointer to the value to the function. The pointer is 64-bits long, so the pointer is the exact same size. But the function then has to _de-reference_ the pointer - lookup the memory address being pointed to, and get the value from there. So the computer has to perform an extra step to get to the value. There’s a Clippy warning in “pedantic” mode that will warn you about this sometimes.

When you compile in _release_ mode, LLVM (the underlying compiler system) is often smart enough to transform a read-only pointer into a copy. It’s also smart enough to realize that if it puts the value into a register earlier and “inlines” the function call (literally copy it inline into the calling code) it can skip copying/passing altogether. It doesn’t always get that right, but it usually does. (“RVO - Return Value Optimization” can cause “copy elision” to happen, often eliminating the entire copy. It’s not guaranteed to happen in Rust, but it usually does)

So, that’s great - but there _are_ times you want to be referencing `Point` rather than copying it. Every time you are getting one out of Legion, a reference is preferable because you are operating on the original value in Legion’s data store. If you are updating the point (with an `&mut`) you absolutely have to use a reference - otherwise your updates won’t apply to the original. When you are accessing a bunch of `Point` values, you tend to gain more from them being adjacent in cache than you lose from the pointer jump - a jump to something in L1 cache is effectively instant.

Hope that wasn’t too long an explanation. **TLDR** : it’s fixed for beta 2, thank you for spotting it.

---

_[View the full topic](https://forum.devtalk.com/t/hands-on-rust-chapter-7-invalid-camera-method-from-chapter-5/4282)._
