rust-si
rust-si copied to clipboard
Read on other type of string
This is an interesting crate, but why limit it to the stdin ? I was interested to use it on string. An why not files ?
Maybe we can have a second argument for this, defaulting to stdin()
so
let stuff: String = read!("<b><i>{}</i></b>");
would be equivalent to
let stuff: String = read!("<b><i>{}</i></b>", stdin());
so that we could do
let stuff: String = read!("<b><i>{}</i></b>", html_input_string);
@sinistersnare agree
sorry, this issue must've gotten lost in my emails... That's a great Idea, I'll address it.
Doing files is hard... You usually want to continue reading in the file with a new read!
call or similar... so right now it looks like
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);
assert_eq!(val, 42);
let s: String = read!("There is {} spoon", file);
assert_eq!(s, "no");
Which is quite a mouthful for reading from a file.
Until we get impl specialization, there's not much I can do except add a macro for turning a filename into a bytes iterator to the file.