How do I use the SHIFT-JIS encoding in Rust?

大城市里の小女人 提交于 2019-12-06 22:32:45

encoding_rs::SHIFT_JIS, a crate made for Firefox, can be used instead! :)

extern crate encoding_rs;
use encoding_rs::SHIFT_JIS;

fn main() {
    let data = vec![142,75,130,209,130,189,142,169,147,93,142,212,130,198,141,98,138,107,151,222];
    let (res, _enc, errors) = SHIFT_JIS.decode(&data);
    if errors {
        eprintln!("Failed");
    } else {
        println!("{}", res);
    }   
}

Outputs:

錆びた自転車と甲殻類

Note that res is a Cow<'_, str> - you may need to use into_owned() depending on your use case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!