HNHacker News
TopNewBestAskShowJobs

veber-alex

745 karma · joined November 1, 2021

submissionscomments
veber-alex··on Rust: A Critical Retrospective
its coming soon, already available on nightly.

   let Some(x) = foo() else { return 42 };
veber-alex··on Rust: A Critical Retrospective
GP's code will return Result<_, Bar>, the original code we are trying to fix just returns Bar.
veber-alex··on Rust: A Critical Retrospective
Bar::Fail is not wrapped in a Result type, so you can't use '?' with it (on stable at least).

You can write it like this:

  let foo_result = match foo() {
    Ok(v) => v,
    Err(e) => return Bar::Fail(e)
  };
veber-alex··on Rust: A Critical Retrospective
let me introduce you to the famous '?' operator.

The code above can be written as:

  let foo = foo()?;
veber-alex··on Rust: A Critical Retrospective
I don't see how that is all that different from Rust.

The main difference I see is that in Rust it will also work with your own custom types, not just optional.

  fn make_bla() -> Option<Bla> {
    // this either returns a valid Bla, or None
  }

  if let Some(bla) = make_bla() {
    // bla is now the unwrapped valid type
  } else {
    // make_bla() returned None
  }
..or with the '?' operator (early return)

  let bla = make_bla().ok_or(InvalidBla)?;
..or with let_else (nightly only but should be stable Soon(tm))

  let Some(bla) = make_bla() else { return Err(InvalidBla) }
..or panic on None

  let bla = make_bla().unwrap();
veber-alex··on Rust: A Critical Retrospective
Go is not a systems programming language.

I also personally find Go syntax to be horrible, especially now with generics.

veber-alex··on Rust: A Critical Retrospective
You linked to docs of 3 python projects and each one looks entirely different while the docs of all rust crates look exactly the same.
veber-alex··on Rust extension traits, greppability and IDEs
I suggest you start reading the compiler error messages as they say exactly what trait is missing, no need to waste an hour.

For example for this code:

  trait Foo {
      fn foo(&self) {}
  }

  struct Bar;

  impl Foo for Bar {}

  mod test {
      use super::Bar;
      fn test() {
          Bar.foo();
      }
  }


  22 |         Bar.foo();
     |             ^^^ method not found in `Bar`
     |
     = help: items from traits can only be used if the trait is in scope
  help: the following trait is implemented but not in scope; perhaps add a `use` for it:
     |
  20 |     use crate::Foo;
     |
veber-alex··on Rust extension traits, greppability and IDEs
As mentioned in that github thread, this works in JetBrains IDEs.

For rust-analyzer it's blocked on improvements in Chalk.

veber-alex··on Rust extension traits, greppability and IDEs
You should not be using the RLS extension, it hasn't been updated in over a year.

Instead you should use rust-analyzer which will soon become the official rust extension.

https://marketplace.visualstudio.com/items?itemName=matklad....

veber-alex··on The future of Python build systems and Gentoo
cargo itself does need TOML support to build because cargo itself is a Rust crate [0].

But it's not a problem because you build a new version of cargo with an older version of cargo that of course can parse TOML.

[0] https://github.com/rust-lang/cargo/blob/master/Cargo.toml

veber-alex··on C++ Coroutines Do Not Spark Joy
The only thing new in Rust 2018 is the impl Trait in argument position.

Generics and trait bounds are in the language from the start.

So you can write this function like this:

  fn twiddle<T: IntoIterator<Item = Foozle>>(foozles: T)
Which is 100% idiomatic today and is even preferred by some people over using impl Trait
← PreviousPage 8 of 8