Read formatted input from file (once more)

So, first of all, I'm a noob in Rust.

I am trying to do something really simple, which is to read formated data from a text file (mainly floating points from a database). I have looked around the web for StackOverflow-like solutions on this and stumbled on some very convoluted, Java-reeking ways to do that (which, due to the newness of the language, I have no idea if will even compile). Recently, I have seen that there is a text-io crate or something like that here (the last update on that was Oct'15). But...

Will there ever be any standard and simple way to do that (like scanf, or matlab's importdata)? Is this a design decision I am not aware of?

Sorry if this question is already beaten up to death. I just cannot figure it out.

As far I know, there's nothing in the language that stops people from writing handy library code for I/O (with just some panics sprinkled on top). So it's a cultural thing.

crate scan-rules has a nice interface. (I'm curious what you think about it @tokahuke)


Wow! Thanks! It seems the right tool for the job... I like it.
And... I didn't know Rust macros could do THAT kind of stuff!

Got me more interested in this whole Rust business.

1 Like

The standard library has very primitive ways of getting input, see the "Guessing Game" chapter of the book for an example.

The text-io crate you mentioned is what @leonardo is talking about: an external package with a simple interface.

Putting stuff in the standard library is a commitment to keep it stable for all time; Rust has a tiny standard library, by comparison. Don't hesitate to use packages. At some point, we expand std, but only once things probe very mature. As an example, Regex has had a stable interface for over a year now, but is still not in std.


Yes, I understand, and I think Rust is doing the right thing here. I will need some more time to adjust, and break my older-style coding habits.