rust-si icon indicating copy to clipboard operation
rust-si copied to clipboard

Read on other type of string

Open gbersac opened this issue 9 years ago • 4 comments

This is an interesting crate, but why limit it to the stdin ? I was interested to use it on string. An why not files ?

gbersac avatar Aug 29 '15 20:08 gbersac

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 avatar Oct 12 '15 18:10 sinistersnare

@sinistersnare agree

gbersac avatar Oct 12 '15 19:10 gbersac

sorry, this issue must've gotten lost in my emails... That's a great Idea, I'll address it.

oli-obk avatar Oct 13 '15 07:10 oli-obk

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.

oli-obk avatar Oct 13 '15 08:10 oli-obk