2
2

More than 5 years have passed since last update.

Rust エンコーディング メモ

Last updated at Posted at 2018-04-19

ベクタ->スライス->文字列

extern crate encoding_rs;

use encoding_rs::*;

let v = vec![0x61, 0x62, 0x63];
let (cow, encoding_used, had_errors) = UTF_8.decode(&v[..]);
println!("{:?}", cow);

ベクタ->バイト列->文字列

extern crate bytes;
extern crate encoding_rs;

use bytes::Bytes;
use encoding_rs::*;

let v = vec![0x61, 0x62, 0x63];
let b = Bytes::from(v);
let (cow, encoding_used, had_errors) = UTF_8.decode(&b);
println!("{:?}", cow);
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2