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

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

$
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_lossy(&buffer[..]);

and I need to decode from ascii, so I am asking for if an analogue of String::from_utf8_lossy() 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_lossy(&buffer[..]);

Thanks!


Viewing all articles
Browse latest Browse all 1216

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>