Search code examples
rust

What happens when you clone a `&str`?


What happens when you clone a &str?

Is the cloned &str pointing to the same place as clonee &str or is it something?

Is this documented anywhere?


Solution

  • Cloning a &str is the same as cloning any &T; it just copies the reference.

    Clone is implemented for any &T. It literally just returns itself since it is Copy.

    This is documented under reference's docs.