News for hackers. Stuff that matters.
Re:The Rust I wanted had no future by Ygg2 on Monday June 05, 2023 @06:03PM (#36204603)
>Are you saying that Rust will refuse to compile code that does not explicitly

Depends what you mean by explicit.

Look at it like this:

    pub fn main() { 
      let mut vec : Vec<i32> = vec![];
      let x = vec.pop();
      println!("{:?}",x); // prints: None
    }
In this case you see the value is missing.

    vec.pop().expect("I want a value") 
will panic with "I want a value" because value is empty. And most rigorous way to deal with it is:

    if let Some(x) = vec.pop() {
       println!("{:?}",x); 
    } else {
       println!("EMPTY"); // prints: Empty
    }
will either print value or EMPTY depending on what the vector contains.

Types like Result will issue warning that you didn't handle the cases.

Re:The Rust I wanted had no future by FpUser on Monday June 05, 2023 @07:19PM (#36205704)
So instead of checking if vector is not empty you check that the return result is not empty. I do not see much difference. If Rust compiler would choke when "else" clause in your example is not present I would understand your point about compiler preventing improper access.
Re:The Rust I wanted had no future by dtn on Monday June 05, 2023 @07:38PM (#36205918)
`x`, the value of the Vector access, only exists within the context of the first block. It does not exist in any other scope. This makes it impossible to access when the result is not valid.

> If Rust compiler would choke when "else" clause in your example is not present

The compiler won't choke, but it will stop you from accessing the value.

It doesn't matter if you omit the `else` clause or not, the type system ensures that you can't access invalid values.

Here's a bit of an example based off of @Ygg2's code: https://play.rust-lang.org/?version=stable&mode=debug&editio...

Re:The Rust I wanted had no future by steveklabnik on Monday June 05, 2023 @10:53PM (#36207483)
> for some reason I can not answer your subsequent reply so I do it here

Hacker News will try and discourage really quick back and forth comments. To do so, the reply button is hidden. However, if you click on the timestamp, to go to the comment's own page, you can reply there.

Re:The Rust I wanted had no future by FpUser on Tuesday June 06, 2023 @11:18AM (#36214170)
Thanks for the tip. Did not know it