1个不稳定版本
使用旧的Rust 2015
0.1.0 | 2018年2月24日 |
---|
在编码类别中排名第1225
每月下载量达9,855次
在14个crate(直接使用7个)中使用
33KB
386 行
codepage-437
为Rust编写的Code page 437转码。
文档
lib.rs
:
将数据转换为和从codepage 437。
使用{Borrow,}FromCp437
traits将一系列cp437字节转换为Unicode,并使用cp437_to_unicode()
函数解码单个码点。
使用{Into,To}Cp437
traits将Unicode转换为一系列cp437字节,并使用unicode_to_cp437()
函数编码单个码点。
示例
从缓冲区借用
let data = &[/* buffer acquired somewhere */];
/// in_unicode will be Cow::Borrowed if data only contains overlapping characters,
/// or Cow::Owned if a conversion needed to have been made.
let in_unicode = Cow::borrow_from_cp437(data, &CP437_CONTROL);
// Also valid:
let in_unicode = String::borrow_from_cp437(data, &CP437_CONTROL);
从缓冲区中移出
let data = vec![/* buffer moved in from somewhere */];
/// data is moved out of and zero-alloced into in_unicode
/// if it only contains overlapping characters
let in_unicode = String::from_cp437(data, &CP437_CONTROL);
从&str
借用
let data = "Some string.";
/// in_cp437 will be Cow::Borrowed if data only contains overlapping characters,
/// Cow::Owned if a conversion needed to have been made,
/// or Err, if data can't be represented as cp437
let in_cp437 = data.to_cp437(&CP437_CONTROL);
// Also valid (String is AsRef<str>):
let data = "Some string.".to_string();
let in_cp437 = data.to_cp437(&CP437_CONTROL);
从String
中移出
let data = "Some string.".to_string();
/// data is moved out of and zero-alloced into in_cp437
/// if it only contains overlapping characters
let in_cp437 = data.into_cp437(&CP437_CONTROL);
无法表示的Unicode
// Ż has no representation in cp437
let data = "Jurek żelaznym żurkiem żre żupan.";
let result = data.to_cp437(&CP437_CONTROL);
assert!(result.is_err());
// result.unwrap_err() is Cp437Error (or IntoCp437Error for into_cp437()),
// with an API modeled after libstd's {From,}Utf8Error
无运行时依赖
~170KB