How do I get a
&str
-
Use
Borrow
:use std::borrow::Borrow; alphabet.push_str(example.borrow());
-
Use
AsRef
:alphabet.push_str(example.as_ref());
-
Use
Deref
explicitly:use std::ops::Deref; alphabet.push_str(example.deref());
-
Use
Deref
implicitly through a coercion:alphabet.push_str(&example);
How do I get a
String
-
Use
ToString
:example.to_string();
-
Use
Cow::into_owned
:example.into_owned();
-
Use any method to get a reference and then call
to_owned
:example.as_ref().to_owned();