A blag post on a first project

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

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.

8 Likes

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

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

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.

@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()?

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<()>.

1 Like

cool that is good to learn!