Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert &[u8] to String [duplicate]

Tags:

types

rust

I have a byte array which I would like to return as std::string::String. The other answers and docs I found were converting Vectors to strings.

How would I convert a byte array &[u8] to a String?

like image 706
Qwertie Avatar asked May 20 '18 13:05

Qwertie


People also ask

How do you convert units of measure?

Summary: to convert units, construct a fraction that is equal to 1, multiply the original measurement by that fraction, and simplify.

Will credit card convert currency?

Usually you'll have to pay a fee to convert currency on your credit card (the currency conversion rate). The rate that's used may vary depending on the credit card network (e.g. Visa, Mastercard, American Express) and the type of currency conversion you select at the time of purchase.


1 Answers

It's working with std::str::from_utf8:

std::str::from_utf8(byte_array).unwrap().to_string();

Playground

like image 165
Tim Diekmann Avatar answered Sep 18 '22 02:09

Tim Diekmann