News for hackers. Stuff that matters.
Re:Tracking Trust with Rust in the Kernel by menaerus on Friday September 19, 2025 @05:16AM (#45299599)
You said

> With a standard library and culture built on exposing the edge cases at compile time.

So, how exactly is "you need to acknowledge that the path may be invalid" from your example a compile-time trait? That's certainly not something you know during the compile-time, and if so, then you should be treating all the files like that, so, I see no difference here wrt other languages.

Re:Tracking Trust with Rust in the Kernel by ViewTrick1002 on Friday September 19, 2025 @05:25AM (#45299654)
Take the function signature:

  pub fn to_str(&self) -> Option<&str>
An option is an enum (tagged union)

  pub enum Option<T> {
      None,
      Some(T),
  }
To get the data out of the Some variant you need to match on it. If you don't cover the the None variant with a choice it will not compile.

  let my_valid_string = match path.to_str() {
      Some(path) => path,
      None => todo!("Cover invalid unicode case"),
  }
You can see this in the playground here were I deliberately did not cover the None path leading to the compiler telling me I need to make a choice.

https://play.rust-lang.org/?version=stable&mode=debug&editio...

We can't know if a generic path is valid at compile time. But we can at compile time ensure that we must acknowledge and make a choice for the invalid case.

This now (in)famous blogpost on Go is what happens when you just pretend that everything works:

https://fasterthanli.me/articles/i-want-off-mr-golangs-wild-...

Re:Tracking Trust with Rust in the Kernel by johnisgood on Friday September 19, 2025 @08:12AM (#45300736)
OCaml, Haskell, Kotlin, and Swift has this, too...
Re:Tracking Trust with Rust in the Kernel by scns on Friday September 19, 2025 @09:57AM (#45301737)
There are at least some unikernels written in OCaml IIRC, don't know about kernells written in Haskell.
Re:Tracking Trust with Rust in the Kernel by johnisgood on Friday September 19, 2025 @10:18AM (#45301950)
Re:Tracking Trust with Rust in the Kernel by menaerus on Saturday September 20, 2025 @02:25AM (#45310950)
> We can't know if a generic path is valid at compile time. But we can at compile time ensure that we must acknowledge and make a choice for the invalid case.

While a pragmatic choice, in reality it isn't very practical IMO. Most of the times you really don't know what to do with the error so you end up turning the condition either into an exception, because it really is an exceptional case, and/or assert on it as an invariant that is broken and which you believe is a programming (usage) error. In any case, you don't really know how to handle it well, and this is I believe often the case for kernel design too - they will try to eliminate as much as possible such cases with testing because they can't afford to panick during the runtime because that would actually be detrimental for QoS.

Even in C++ you have something not quite the same but similar with [[nodiscard]] qualifier but in practice I haven't really seen it being used much but when I did it was mostly annoying to deal with. It's like a hot potato that is being thrown across the API boundaries but nobody wants to deal with it.