std::io::Write a Vec<char>?

Is there a safe way to write a Vec<char> into any impl std::io::Write without re-buffering?

If not, is there an unsafe way given that Vec<char> hopefully equals a continuos buffer of u8 bytes that resolve to a valid utf-8 sequence?

It's better to just use a String than Vec<char>. String already implements Write, uses less memory than Vec<char>, and it is guaranteed to be UTF-8

1 Like

"Equals" in the sense that it could be converted into a continuous buffer of u8s, but a Vec<char> is not represented as a buffer of u8s — that's what str and String are. A Vec<char> is represented like a Vec<u32>.

Hmm I guess since char is actually a 4byte sequnce using a String really does make more sense for this use case.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.