Skip to main content

in reply to JordiGH

For future reference, cargo help and cargo --list will show you commands that are available to you. That's easier that guessing.
in reply to JordiGH

Whaaaaat, no type deduction?

Man, I'm already not having fun. I'm going to have to specify the type of everything? I can't just say, "type is whatever the return type of that thing is"?

in reply to JordiGH

It will figure out the type if it can, but .collect can output many different types. If you want to tell it to collect to a vec for example you can just to .collect::<Vec<_>>();
in reply to Sigma

@sigma Yup, exactly this - there's no way for the compiler to know what you want to collect to, because collect is generic.
in reply to Chris 🌱

@brainblasted @sigma idk, I just wanted the CLI args as strings, is this the shortest way to say it?
in reply to JordiGH

@brainblasted It's not the shortest way, but I think this way looks nicer. The other way is to give the variable a type like this `let args: Vec<_> = ...` which ls a few chars shorter. Also, this article may be helpful techblog.tonsser.com/posts/wha….
This entry was edited (1 year ago)
in reply to Sigma

@sigma @brainblasted I mean, I gotta use collect with ambiguous type? Why isn't `env::args()` just a vector of strings already?
in reply to ✌🏿✍🏿

@jalcine @sigma @brainblasted Hehe, I don't know yet what this means. Serialize? I want strings. The strings I type at the command line. Whitespace-separated. As sent by the OS. Why do I need to serialize?
in reply to JordiGH

@jalcine @sigma collect() is a generic function on iterators, and iterators are generic. While the Args iterator on Strings, my understanding is that you can use collect() to collect a vector of anything you could convert a string to.