當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Rust u8.escape_ascii用法及代碼示例

本文簡要介紹rust語言中 u8.escape_ascii 的用法。

用法

pub fn escape_ascii(&self) -> EscapeDefault

返回生成 u8 的轉義版本的迭代器,將其視為 ASCII 字符。

該行為與 ascii::escape_default 相同。

例子

#![feature(inherent_ascii_escape)]

assert_eq!("0", b'0'.escape_ascii().to_string());
assert_eq!("\\t", b'\t'.escape_ascii().to_string());
assert_eq!("\\r", b'\r'.escape_ascii().to_string());
assert_eq!("\\n", b'\n'.escape_ascii().to_string());
assert_eq!("\\'", b'\''.escape_ascii().to_string());
assert_eq!("\\\"", b'"'.escape_ascii().to_string());
assert_eq!("\\\\", b'\\'.escape_ascii().to_string());
assert_eq!("\\x9d", b'\x9d'.escape_ascii().to_string());

相關用法


注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 u8.escape_ascii。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。