Skip to content

Read on other type of string #4

Open

Description

@gbersac

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

Activity

  1. sinistersnare commented on Oct 12, 2015

    @sinistersnare

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

  2. gbersac commented on Oct 12, 2015

    @gbersac
    Author
  3. oli-obk commented on Oct 13, 2015

    @oli-obk
    Owner

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

  4. self-assigned this
    on Oct 13, 2015
  5. oli-obk commented on Oct 13, 2015

    @oli-obk
    Owner

    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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions