Skip to content

Converting BStr/BString to std::String #172

Closed Answered by BurntSushi
RAnders00 asked this question in Q&A
Discussion options

You must be logged in to vote

A BStr can be converted to a &str via ByteSlice::to_str. It's one of the first methods listed on the trait. And if s is a &str, you can get a String via s.to_string().

A BString can be converted to a String via ByteVec::into_string.

There are also TryFrom impls for TryFrom<&BString> for &str and TryFrom<BString> for String. Analogously, there is also TryFrom<&BStr> for &str and TryFrom<&BStr> for String.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@BurntSushi
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants