How to convert non-UTF8 encoded Cow<[u8]> to a GBK &str

To enable GBK characters to be displayed on a gui title (using GitHub - Boscop/web-view: Rust bindings for webview, a tiny cross-platform library to render web-based GUIs for desktop applications), I encoded a utf8 str using GBK encoding into Cow<[u8]>, and tried to convert the result into a GBK &str, but failed. Is there any method available to show the title properly?

A str is always utf-8 -- why are you trying to use GBK?

Because the web-view lib doesn't display GBK characters properly in title. In golang, I can use string(GBK encoded bytes) to show it correctly. But in rust, I have no idea.

Wait, so you have GBK input that you've already converted to utf-8 bytes? Then str::from_utf8 should do the rest of the job. If that doesn't work, can you show the code you are trying?

Thanks for your help. It seemed that the title type should be changed from &str to impl Into<Vec<u8>> , so that GBK encoded [u8] can be displayed properly in the title. I have submitted an issue.

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