How to convert Vec<char>
to string form so that I can print it?
相关问题
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Share Arc between closures
- Converting a string array to a byte array
- Function references: expected bound lifetime param
相关文章
- How can I convert a f64 to f32 and get the closest
- JSP String formatting Truncate
- What is a good way of cleaning up after a unit tes
- Selecting only the first few characters in a strin
- Python: print in two columns
- extending c++ string member functions
- Google app engine datastore string encoding proble
- How can I unpack (destructure) elements from a vec
Here is a more readable version that consumes the vector:
Note that
collect
is implemented with a call toFromIterator::from_iter
:Use
collect()
on an iterator:The original vector will be consumed. If you need to keep it, use
v.iter()
:There is no more direct way because
char
is a 32-bit Unicode scalar value, and strings in Rust are sequences of bytes (u8
) representing text in UTF-8 encoding. They do not map directly to sequences ofchar
s.Docs:
std::str::from_chars
(The latter can be used to collect to a
~str
too, just by changing theStrBuf
type hint.)