3 ms·
IMO the issue here is with the question mark operator. If the Rust question mark operator was more like Kotlin's this wouldn't be an issue.
by pirocks 6y ago
IMO the issue here is with the question mark operator. If the Rust question mark operator was more like Kotlin's this wouldn't be an issue.
- fanf2 6y agoIt looks like Kotlin uses ? for nullable types, which isn’t really anything to do with Rust’s ? for short-cut error handling. https://kotlinlang.org/docs/reference/keyword-reference.html https://kotlinlang.org/docs/reference/keyword-reference.html You can also use ? with Option: fn process_item(input: Option<Item>) -> Option<Item> { let item = input?; Some(item + 3) }
- masklinn 6y agoI'm guessing they're referring the `?.` "safe calls" operator[0-] which essentially acts as a mix of `map` and `andThen` except only for property accesses and method calls, and can be combined with `let` for a more general map-like behaviour. [0] where many conceive of the operation as `?` being a modifying operator to `.`
- pirocks 6y agoIn kotlin your example would be: fun process_item(input: Item?) -> Item? { input?.plus(3) } This would have to be modified in rust to apply to both error and option types, as well as working on stuff other than the . operator, but I think it could be made to work. The main difference is that the ?. operator in kotlin works at the expression level, instead of the function level.