"Structural pattern matching" for Python, part 2
"Structural pattern matching" for Python, part 2
Posted Sep 2, 2020 7:24 UTC (Wed) by ehiggs (subscriber, #90713)In reply to: "Structural pattern matching" for Python, part 2 by NYKevin
Parent article: "Structural pattern matching" for Python, part 2
You are correct that a PyObject is a tagged union. The point here, however, is that match in Rust is exhaustive. You must write the match case for every possible branch if you want your Rust code to compile. Making match on PyObject exhaustive would mean you need a branch covering all possible types.
Since so many things can be a PyObject, this isn't feasible unless you just had a fallthrough case (in Rust this uses _). The problem then is that you will never catch bugs when extending the code because you will happily use the fall through case when a new field in the enum is added.
