3 ms·
V's Maybes are different than Rust's, only the ? syntax is similar 1. Option/Result are unified into a single type, ?T. 2. It is not parameterized over the er
by edflsafoiewq 6y ago
V's Maybes are different than Rust's, only the ? syntax is similar
1. Option/Result are unified into a single type, ?T.
2. It is not parameterized over the error type.
3. The Ok() case does not need to be marked (ex. you write 1, not Ok(1)).
4. In addition to the x? sugar, there is also x or { ... } sugar, which is like Rust's x.unwrap_or(|err| ...) except without the closure so you can eg. break or return from the block. There is also if y := x { .. } else { ... }, which is like Rust's match x { Ok(y) => ..., Err(err) => ... }.
These are all reasons you could think V has cleaner Maybe handling than other languages.
- vlang1dot0 6y ago> 1. Option/Result are unified into a single type, ?T. This is not a positive. Option<T> and Result<T, E> have semantically different meanings. This is like saying integers and strings have been unified into a single type: string.