operator ~ method
- @Deprecated('Use `Result.call()` as `value()` to unwrap `Result` type values instead.')
Deprecated: Use Result.call()
as value()
to easily unwrap Result
type values instead.
Shortcut to call Result.unwrap().
Warning: This is an unsafe operation. A ResultError will be thrown if this operator is used on an Err value. You can take advantage of this safely via catchResult/catchResultAsync.
var foo = Ok(1);
var bar = Ok(2);
print(~foo + ~bar); // prints: 3
Note: if you need to access fields or methods on the held value when
using ~
, you'll need to use parentheses like so:
var res = Ok(1);
print((~res).toString());
Additionally, If you need to perform a bitwise NOT on the held value of
a Result
, you have a few choices:
var res = Ok(1);
print(~(~res)); // prints: -2
print(~~res); // prints: -2
print(~res.unwrap()); // prints: -2;
See also:
Rust: Result::unwrap()
Implementation
@Deprecated('Use `Result.call()` as `value()` to unwrap `Result` type values instead.')
T operator ~() => unwrap();