Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oli-obk/rust-si
a rusty `scanf` (`scan!`) and inverse of `print!` (`read!`)
https://github.com/oli-obk/rust-si
io macros rust scan
Last synced: 11 days ago
JSON representation
a rusty `scanf` (`scan!`) and inverse of `print!` (`read!`)
- Host: GitHub
- URL: https://github.com/oli-obk/rust-si
- Owner: oli-obk
- License: mit
- Created: 2015-04-16T14:09:54.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-07-12T05:47:01.000Z (over 1 year ago)
- Last Synced: 2024-10-08T07:10:43.969Z (about 1 month ago)
- Topics: io, macros, rust, scan
- Language: Rust
- Homepage:
- Size: 73.2 KB
- Stars: 188
- Watchers: 4
- Forks: 15
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.Apache-2.0
Awesome Lists containing this project
README
![Build Status](https://github.com/oli-obk/rust-si/actions/workflows/rust.yml/badge.svg)
[![Latest Version](https://img.shields.io/crates/v/text_io.svg)](https://crates.io/crates/text_io)You can use either the `read!` macro to read a single value and return it, or
the `scan!` macro to read one or more values into variables. Both macros can
also read from a file or from memory. The `read!` macro can take any type that
implements `Iterator` as an optional third argument, and the `scan!`
macro's arguments can be prefixed with `iter => ` where `iter` implements
`Iterator`.# Examples
## scan! macro
```rust
use text_io::scan;// reading from a string source
let i: i32;
scan!("12".bytes() => "{}", i);
assert_eq!(i, 12);// reading multiple values from stdio
let a: i32;
let b: &mut u8 = &mut 5;
scan!("{}, {}", a, *b);
```## read! macro
```rust
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 "" or panic
// read until the next "<" and return that.
// expect the input "/i>"
let stuff: String = read!("{}");// 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());
```