4 个版本
0.8.3 | 2023年4月17日 |
---|---|
0.8.2 | 2023年4月6日 |
0.8.1 | 2023年4月5日 |
0.8.0 | 2023年4月5日 |
1358 在 文本处理 中
每月下载 35 次
10KB
130 行
encode_rs_transcode
此库允许您轻松在写入器中进行文本转码。
转码由 encoding_rs 执行,此库仅提供了一个简单的构建器,以便与外部写入器轻松使用。
用例
- 以特定格式写入文件(例如,使用 csv crate)写入 CSV 文件
示例
extern crate csv;
use std::fs::File;
use encoding_rs_transcode::{encoding_rs::WINDOWS_1252, TranscoderBuilder};
fn main() {
// Create a file writer
let file = File::create("test.csv").unwrap();
// Create a transcoder that'll transcode the input to WINDOWS_1252
let transcoder_writer = TranscoderBuilder::new()
// .from_encoding(UTF_8) // implied by new()
.to_encoding(WINDOWS_1252)
.build_writer(file);
// Create a CSV writer
let mut csv_writer = csv::Writer::from_writer(transcoder_writer);
// Write to the CSV file
csv_writer.write_record(["foo", "bar"]).unwrap();
csv_writer.write_record(["aceio", "àcéîö"]).unwrap();
// The CSV file will now be encoded in WINDOWS_1252, without the CSV crate ever
// aknowledging the final encoding.
// This can be applied to any writer implementing the `Write` trait.
}
依赖关系
~3MB
~118K SLoC