Function e_utils::system::encode::decode

source ·
pub fn decode<'a>(
    content: &[u8],
    decode_labels: &'a [&'static Encoding],
) -> Option<String>
Expand description

通过预设解码

use e_utils::system::encode::{DEFAULT_ENCODE_LABEL_LIST, decode};
fn main() {
    let stdout = b"out -> \xe4\xbd\xa0\xe5\xa5\xbd: \xe6\x88\x91\xe4\xb8\x8d\xe8\x83\xbd\xe8\xae\xa4\xe8\xaf\x86\xe8\xaf\xad\xe8\xa8\x80\r\n\r\n Windows \xe6\x9c\xaa\xe6\xbf\x80\xe6\xb4\xbb";
    let txt = decode(stdout, &DEFAULT_ENCODE_LABEL_LIST)
        .unwrap_or_else(|| String::from_utf8_lossy(stdout).to_string());
    println!("{:?}", txt);
}