I think there needs to be a "center the page" browser extension because this is just absurd: https://imgur.com/a/HZqaA4V
Nibbles of Rust – Restructuring Patterns
21–30 of 31 posts
Re: Nibbles of Rust – Restructuring Patterns
#22The author talks about adding structure, and I've been puzzled about what they are talking about until realizing that they apparently mean that a reference to something is "more" than the something hence it "adds structure". That doesn't make sense to me. More structure is if there are more elements in the data (more fields in a struct, or more alternatives in an enum), whereas a reference is just an indirection of a…
Re: Nibbles of Rust – Restructuring Patterns
#23I think there needs to be a "center the page" browser extension because this is just absurd: https://imgur.com/a/HZqaA4V
Re: Nibbles of Rust – Restructuring Patterns
#24Since the author mentions at the end that they were motivated to write and publish this as a part of a writing group, I'd like to say that this was a very pleasant read. Tightly-scoped but insightful and informative!
Re: Nibbles of Rust – Restructuring Patterns
#25I think there needs to be a "center the page" browser extension because this is just absurd: https://imgur.com/a/HZqaA4V
I always thought it was weird when people have websites like this, anyways, for those phased away and want to read this article while centered, execute in the console: document.getElementsByTagName('body')[0].children[0].style.margin = '0 auto';
document.getElementById('wrapper').style.margin = '0 auto';
Though if you're in the habit of customizing sites you read, I'd personally recommend using a browser extension like Stylus (https://add0n.com/stylus.html) to do CSS, so you could write it like this: #wrapper {
margin: 0 auto;
}Re: Nibbles of Rust – Restructuring Patterns
#26Earlier quoted context omitted.
I always thought it was weird when people have websites like this, anyways, for those phased away and want to read this article while centered, execute in the console: document.getElementsByTagName('body')[0].children[0].style.margin = '0 auto';
That's a good tip! I also think its just as weird when sites have zero links to their home page. On what planet is "go to the address bar and delete the last part of the url and hit enter to go to the index" good user experience?
My goal in leaving out the link to my home page was to make the Writing Gaggle home page more prominent than my personal blog. (I manage hosting both, see.) I only added my blog index page as an afterthought when I saw a ton of 404 errors on my server a few months ago because people were manually navigating to it.
I'll consider adding actual navigation to my page template though, so maybe you'll be less annoyed ;)
Re: Nibbles of Rust – Restructuring Patterns
#27The author talks about adding structure, and I've been puzzled about what they are talking about until realizing that they apparently mean that a reference to something is "more" than the something hence it "adds structure". That doesn't make sense to me. More structure is if there are more elements in the data (more fields in a struct, or more alternatives in an enum), whereas a reference is just an indirection of a…
Let’s consider the case where T is u8. There are 256 inhabitants of the u8 type (0u8-255u8).
Now consider &u8. Each u8 referent is still some value between 0 and 255, but the number of references you could have is dependent on the pointer width of your target system — let’s say 64 bits. So that’s 2^8 possible u8 values times 2^64 possible references, or 2^72 inhabitants. Well, minus one to account for null, and I’m probably missing other details, but you get the idea.
So going from T to &T introduces structure in the same sense that going from T to (T, U) does; and going from &T to T destructures in the same sense that going from (T, U) to T does. That structure may not be directly observable (as in the case of a reference: you’d have to go out of your way to observe the underlying address), but conceptually the structure is there nonetheless.
Edit:
Another way to look at it is this:
Consider a Rust “newtype”, like struct Days(u8).
If you pattern match on that to obtain the inner u8, we call that destructuring. Destructuring is to reduce or break down the structure of a thing, so the opposite must be building up structure, or “restructuring”. Therefore going in the opposite direction — stuffing a u8 value in a Days - must be restructuring. In this case both types have the same number of inhabitants (256); regardless, one direction is destructuring and the other direction is restructuring.
Re: Nibbles of Rust – Restructuring Patterns
#28Earlier quoted context omitted.
What I want is.. let MyEnum(foo, bar, baz) = input but otherwise { do some stuff return some value } Point being I don’t have to check for MyEnum-ness twice (like with matches! + if let) and the indented code is for the exception (no match) not the norm. Tho I … guess !matches(MyEnum{ .. }) is not the worst… but it’s annoying to have this pattern all over my code instead of as some encoded concept we all use
You were pretty close with your hypothetical syntax! You can write: let Some(y) = x else { do_stuff(); return }; I think it was a fairly recent addition to Rust.
Re: Nibbles of Rust – Restructuring Patterns
#29Earlier quoted context omitted.
You were pretty close with your hypothetical syntax! You can write: let Some(y) = x else { do_stuff(); return }; I think it was a fairly recent addition to Rust.
What determines whether `let Some(y) = x` evaluates to boolean true?
Re: Nibbles of Rust – Restructuring Patterns
#30Earlier quoted context omitted.
You were pretty close with your hypothetical syntax! You can write: let Some(y) = x else { do_stuff(); return }; I think it was a fairly recent addition to Rust.
What determines whether `let Some(y) = x` evaluates to boolean true?
Here the type being matched is:
enum Option {
None,
Some(T)
}
let x = Some(42);
let Some(y) = x else { panic!("None") };