16 个版本

0.1.12 2022年7月29日
0.1.10 2022年2月17日
0.1.9 2021年7月29日
0.1.8 2020年1月14日
0.1.0 2015年5月12日

#40文本处理

Download history 7082/week @ 2024-03-14 9558/week @ 2024-03-21 7004/week @ 2024-03-28 8680/week @ 2024-04-04 7977/week @ 2024-04-11 10464/week @ 2024-04-18 8190/week @ 2024-04-25 8006/week @ 2024-05-02 9491/week @ 2024-05-09 14412/week @ 2024-05-16 9727/week @ 2024-05-23 8750/week @ 2024-05-30 9184/week @ 2024-06-06 8569/week @ 2024-06-13 8465/week @ 2024-06-20 4656/week @ 2024-06-27

32,753 每月下载量
用于 115 个 crates (103 直接)

MIT/Apache

12KB
174

[Build Status Latest Version

您可以使用 read! 宏读取单个值并返回它,或者使用 scan! 宏将一个或多个值读取到变量中。这两个宏也可以从文件或从内存中读取。 read! 宏可以接受任何实现了 Iterator<Item=u8> 的类型的任意类型作为可选的第三个参数,并且 scan! 宏的参数可以以 iter => 前缀开头,其中 iter 实现了 Iterator<Item=u8>

示例

scan! 宏

use text_io::scan;

// reading from a string source
let i: i32;
scan!("<b>12</b>".bytes() => "<b>{}</b>", i);
assert_eq!(i, 12);

// reading multiple values from stdio
let a: i32;
let b: &mut u8 = &mut 5;
scan!("{}, {}", a, *b);

read! 宏

use text_io::read;

// read until a whitespace and try to convert what was read into an i32
let i: i32 = read!();

// read until a whitespace (but not including it)
let word: String = read!(); // same as read!("{}")

// read until a newline (but not including it)
let line: String = read!("{}\n");

// expect the input "<b><i>" or panic
// read until the next "<" and return that.
// expect the input "/i></b>"
let stuff: String = read!("<b><i>{}</i></b>");

// reading from files
use std::io::Read;
let mut file = std::fs::File::open("tests/answer.txt").unwrap().bytes().map(|ch| ch.unwrap());
let val: i32 = read!("The answer is {}!!!11einself\n", file);

// reading from strings
let val: i32 = read!("Number: {}", "Number: 99".bytes());

无运行时依赖