Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read on other type of string #4

Open
gbersac opened this issue Aug 29, 2015 · 4 comments
Open

Read on other type of string #4

gbersac opened this issue Aug 29, 2015 · 4 comments
Assignees

Comments

@gbersac
Copy link

gbersac commented Aug 29, 2015

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

@sinistersnare
Copy link

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);

@gbersac
Copy link
Author

gbersac commented Oct 12, 2015

@sinistersnare agree

@oli-obk
Copy link
Owner

oli-obk commented Oct 13, 2015

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

@oli-obk oli-obk self-assigned this Oct 13, 2015
@oli-obk
Copy link
Owner

oli-obk commented Oct 13, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants