Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1045

How to decode from ascii in rust? What's the analogue of rust's String::from_utf8()?

$
0
0

I have the following code:

fn handle_client(mut stream: TcpStream) -> () {   let mut buffer = [0; 4096];   stream.read(&mut buffer).expect("read fail");   let path_request: Cow<'_, str> = String::from_utf8(&buffer[..].to_vec()).unwrap();

and I need to decode from ASCII, so I am asking if an analogue of String::from_utf8 exists for ASCII encoding?

I need the code to be alike:

fn handle_client(mut stream: TcpStream) -> () {   let mut buffer = [0; 4096];   stream.read(&mut buffer).expect("read fail");   let path_request: Cow<'_, str> = String::from_ascii(&buffer[..].to_vec()).unwrap();

Viewing all articles
Browse latest Browse all 1045

Trending Articles