If you look at the String
documentation, there are a few methods you could use. There’s String::from_utf8
that takes a Vec<u8>
, and there’s also String::from_utf8_lossy
which takes a &[u8]
.
Note that a Vec<T>
is more-or-less an owned, resizable wrapper around a [T]
. That is, if you have a Vec<u8>
, you can turn it into a &[u8]
, most easily by re-borrowing it (i.e. &*some_vec
). You can also call any methods defined on &[T]
directly on a Vec<T>
(in general, this is true of things that implement the Deref
trait).