Rust logo
Rust 1.77.2

Borrow and AsRef

There is a new edition of the book and this is an old link.

A cheap reference-to-reference conversion. Used to convert a value to a reference value within generic code.

fn is_hello<T: AsRef<str>>(s: T) {
   assert_eq!("hello", s.as_ref());

This chapter does not exist in the second edition. The best place to learn more about this is the Rust documentation.