concept primitive type in category rust

appears as: primitive types
Rust in Action

This is an excerpt from Manning's book Rust in Action.

One alternative to refactoring is to simply copy values. Doing this often is typically frowned upon, but it can be useful in a pinch. Primitive types, such as integers, are a good example of that. Primitive types are cheap for a CPU to duplicate. So cheap in fact, that Rust always copies them if it would otherwise worry about ownership being moved.

4.1.2. Special behavior of primitive types

Before carrying on, it may be wise to explain why the first code snippet, that is Listing 4. 1, compiled at all. Indeed, the only change that we make at Listing 4. 3 was to wrap our satellite variables in a custom type. As it happens, primitive types in Rust have special behavior. They implement the Copy trait.

Formally, primitive types are said to possess copy semantics, whereas all other types have move semantics. Unfortunately for learners of Rust, that special case looks like the default case because they typically encounter primitive types first. Listing 4. 5 and Listing 4. 6 illustrate the difference between these two concepts. The first compiles and runs, the other does not. Their only difference is that they use different types.

Listing 4. 5. Demonstrating the copy semantics of Rust’s primitive types (and all types that implement Copy). Values may be accessed
fn use_value(_val: i32) {         #1
}

fn main() {
  let a = 123 ;
  use_value(a);

  println!("{}", a);               #2
}