Counter-intuitively, if you're writing a parser for a programming language, you need it to be a total function. As soon as you build IDE tooling, you need ASTs from invalid or incomplete input.
The parser should return (Ast, List<Error>) rather than Result<Ast, Error>.
miniblog.
Related Posts
I've been compilation buffers in Emacs recently and I really appreciate the error and warning counts shown in the modeline.
I've added the equivalent feature to deadgrep: it shows result counts! Really useful when you're doing big refactorings.
Structs are great in Rust, but sometimes I find them a bit heavyweight. There's a little more syntax than e.g. OCaml, for type definitions and usages.
I end up using more structs (records) in OCaml as a result.
rust-analyzer has "convert tuple to named struct", which helps.
Switching between Rust and TypeScript, I really miss the Result type in TypeScript. I can kludge something with nullable types or exceptions, but it's not as nice for the caller.
