First impressions on Rust

I really like the expressiveness of the language. I’m writing code to read GF files from Metafont right now and there’s the Knuthian 1–4 byte parameter reading. This ends up being rather elegant in Rust, particularly the 3-byte version:

pub fn read3<R: Read>(input: &mut R) -> io::Result<i32> {
let mut buf = [0u8; 4]; buf[1..4])?;

This initializes a 4-byte buffer with zeros, fills the last three bytes of that buffer with the next three bytes of the input file and then translates the 4-byte buffer into an integer with big-endian semantics. When I figured out how to do this, I got happy endorphins rushing through my brain. It’s just cleaner than the C++ equivalent 

std::int_fast32_t read3() {
stream->read(buffer, 3);
return static_cast<uint8_t>(buffer[0]) << 16
| static_cast<uint8_t>(buffer[1]) << 8
| static_cast<uint8_t>(buffer[2]);

where I had to assemble the data manually (I didn’t need to declare or initialize the buffer here since in my implementation it was a field in the enclosing class). 

I’m reading three Rust books simultaneously as I learn. My thoughts on the books: The Rust Programming Language by  Steve Klabnik and Carol Nichols is superb. I like reading paper and I got it from the library, but it’s also freely available online (and updated).

Beginning Rust: From Novice to Professional by Carlo Milanesi seems a bit of a hot mess. It introduces things earlier than necessary, especially given its avowed audience. I could have predicted that though, from the publisher. I have yet to see a good book from Apress.

I’ve only just started Programming Rust: Fast, Safe Systems Development by Jim Blandy and Jason Overdorff so I have no opinion on that one yet. 

I’m a bit disappointed with the Rust plugin for CLion. I’ve gotten spoiled by Jetbrains’s support for Java and C++ in their IDEs where the IDE provide a lot of input-time checking and suggesting for me. It made getting back into C++ a lot easier. With Rust, numerous errors don’t actually show up until a proper compilation is run, and the suggestions for resolving issues aren’t always present or useful, particularly around borrowing. IDEs have made me fat and lazy and now I have to work. I don’t like that.

I’ve had questions along the way and it seems like the two online support communities I’ve found aren’t all that great. Neither reddit nor Stack Overflow have seemed adequate. In many instances, the suggestions are completely wrong, but the language and documentation are such that I’ve managed to find my way despite this.

Comments |0|

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: Uncategorized