Thursday, October 26, 2023
Learned about about Rust slices. Increased padding for mobile.
Today's Plan
- Done Finish Rust book ch4.4
- Done Add link to Atom feed to the log
- Done Lengthen whitespace in the footer
Rust Slices
This section was much less intimidating than the previous one (on fixing ownership errors). I'm familiar with slices in Python and MATLAB, which are much more flexible. You can go backwards, and can also skip elements (with a stride size).
Slices in Rust can not do these fancy features. Instead, they can only refer to a contiguous subsection of a data collection. I suspect this is because conceptually, Rust is working closer to the physically-adjacent memory of the stack?
I bet that Rust uses iterators for skipping and going backwards, but I've yet to learn about those in detail.
Fat Pointers
Slices are really simple objects in Rust: just a 'fat pointer'. A fat pointer is a pointer that also has a little bit of data attached (a length, in this case). All string literals in Rust are fat pointers.
I remember learning in an intro CS class that strings in C are just char
bytes that are adjacent in memory, and the program doesn't know when they'll end, it just keeps reading until it encounters a special character that signifies the end. That's something that can easily make you run into memory problems or unpredictable results if you aren't careful. I wonder if this is why Rust chose to bundle some pointers with metadata.
Page Padding
I've given my navigation header and footer some breathing room by increasing the padding of the HTML element. Here's my explanation, quoted from my CSS breakdown:
Instead of having zero padding for the top and bottom, I have added a little at the top, and a lot at the bottom. This is because I was encountering some problems with my header and footer navigation being too close to the edge of the screen on mobile. Either a browser footer covers my footer, or it's too close for comfortable tapping. I don't want buttons to be too close together, because it's an unnecessary barrier for people visiting the site.