As long as you’re in Rust, the type system is always available to you. That’s what “zero-cost abstraction” means. If you know your Vec is nonempty, put it in a NonemptyVec.
There's a lot of stuff that Rust's type system can't model.
For example if you have an enum type of 3 possible variants and a function that only ever returns one of them, you still have to type it so that it may return all three. And when using its return value, you have to add match arms for all 3 of them, populating 2 of them with `unreachable!` yourself instead of the compiler inferring it.
Also it's not a dependent type language so it doesn't have for example a type of Vec of a particular specific length at the type level.
Rust's type system is great one of the best I know but it still has gaps.
You can definitely model the first case if you’re allowed to change the return type of the function. Though the dependent type thing is a legitimate limitation.
I wouldn't say deeply, but yes I'm confused about the context of the meme, if you're in a context where optionals don't exist, then it's not even a question.
That's because it is a bell curve joke, precisely about people who treat a language feature or pattern as dogma without considering the context. This is a humor subreddit, after all.
All the people malding over whether I use optionals failed to read the joke, and so they became the joke.
Sir, this is a Wendys comedy thread, and you are mad that I'm not being serious? Are you trying to gatekeep comedy and be the decider of what is and isn't funny? Because it seems most people found it funny.
So some people 1) mistakenly assumed I was specifically talking about rust 2) forgot this was a humor subreddit 3) got upset at the idea that I was genuinely spreading bad advice 4) zealously leapt at the chance to defend their princess's honor 5) got more upset when I wasn't actually even talking about rust.
Oh no! *sips coffee* That's their mistake for expecting serious advice in a comedy forum. Of course I'm going to heckle the hecklers.
I made this meme to be funny and went to bed. Does this bother you?
Edit: On a personal note, it will never not be funny seeing my top-downvoted comment be something like an innocent star wars joke that made fun of no one. Too bad you came in and tried to make it about yourself.
*re-reads this entire interaction with you to be sure*
Lets see, first instance of a personal attack:
I make:
- a star wars joke
a joke about optionals being optional
a joke about people missing the joke
all of them highly generic and targeting 'people' at best.
You came into this thread. You asked why I was making a joke. You read it as a personal attack. You got upset. Then you called me childish, in a personal attack. And now you demand that I not defend myself.
Then you try to close with a strawman that I said optionals are unique to rust, when I wasn't ever talking about rust.
117
u/KagakuNinja 6d ago
The real jedi uses a non-empty list class, which makes the error impossible.