A blag post on a first project


#1

Hey y’all, I wrote up my first little Rust project.

http://blog.jfo.click/how-rust-do/

Thanks for your help here and in irc land. Feedback is welcome, especially if my terminology or conception is loose anywhere. I don’t want to contribute to putting fuzzy information out in the world.

I enjoyed learning some basics very much, and I’m looking forward to finding more things to use rust for.


#2

Wow, that’s a beast of a post! If you haven’t done so yet, the Rust subreddit may enjoy this post. www.reddit.com/r/rust


#3

@kbknapp oh, no I haven’t! Thanks for the suggestion.


#4

You should use write_all instead of just plain write.
The return value of write denotes the actual number of bytes written which might be less than the amount of bytes you provided.


#5

@troplin that’s interesting, does that mean that a call to write() can “fail” (by failing to write the whole buffer) but still return an Ok()?


#6

write will write at least one byte, but it is not considered an error if not the whole buffer is written.
This is important for networking but when writing to a file this will probably never happen. Still, using write_all is the correct way to do it.

EDIT:
That’s the reason write returns a io::Result<usize> while write_all returns io::Result<()>.


#7

cool that is good to learn!