Conversation

Jarkko Sakkinen

All the crates that #Google has done for #Rust seem to be like stuff I’ve been looking for to get better control of the memory.

Especially zerocopy is a time saver as it has all the thinkable stuff that I have used previously core::slice::from_raw_parts and spent a lot of time thinking of all the possible safety scenarios, such as this recent one:

impl<'a> From<&'a Header> for &'a [u8] {
    fn from(value: &Header) -> Self {
        // SAFETY: out-of-boundary is not possible, given that the size constraint
        // exists in the struct definition. The lifetime parameter links the lifetime
        // of the header reference to the slice.
        unsafe { from_raw_parts((value as *const Header) as *const u8, size_of::<Header>()) }
    }
}

Previously I’ve had to do similar consideration in the #Enarx project. You can do these by hand but it is nice to have a common crate, which is tested by many for these risky scenarios.

Other mentionable crate from Google is tinyvec, which I’m going to use in zmodem2 to remove internal heap usage.

1
0
1
Also this the Rust tutorial I wish I had found when I first started working on with Rust: https://google.github.io/comprehensive-rust/.

It is far better than any e.g. book I've ever seen on the topic of Rust.

At least this is by fart the best tutorial if you already have strong C/C++ and perhaps assembly background. Any books that I've ever read on Rust, well I've stop reading latest on chapter 2 because they have incredibly boring. This is really good hands on engineering material if you already sort of have understanding already topics such as memory management etc.
1
0
2

I’d actually recommend to do few exercises with just from_raw_parts and lifetime parameters before using zerocopy because that sort of gives you full tutorial on what that particular crate does internally :-) I sort of enjoy thinking of those scenarios so it also takes some fun away :-)

0
0
1