points by itishappy 2 days ago | 0 comments
> In Rust, if you have an thing that returns Result<String, String> that's still type safe, even though success and error types are the same.
These types are not the same:
Ok<String>
Err<String>
[–] markasoftware 2 days ago
[–] SkiFire13 2 days ago
Nit: the type constructor is `Result`: given two types `A` and `B` (not instances of those types, but actual types) it gives you a new type `Result<A, B>`.
`Ok` and `Err` are called "variants" and can be used to construct a new _instance_ of `Result<A, B>`.
[–] markasoftware 1 day ago
[–] kazinator 1 day ago
Ok and Err are not just type constructors because they appear on the left hand side in pattern matching: they "do" matching and destructuring also.