okay 0.1.0 okay: ^0.1.0 copied to clipboard
Typesafe error-handling for dart . An implementation of rust's `Result` type in dart.
okay #
Typesafe, intuitive error-handling for dart . An implementation of rust's Result
type in dart.
Note: This package was heavily inspired by rustlang's result type.
Installation #
In the dependencies:
section of your pubspec.yaml
, add the following line:
dependencies:
okay: <latest_version>
Usage #
import 'package:okay/okay.dart';
class FallibleOpSuccess {}
class FallibleOpFailure {}
Result<FallibleOpSuccess, FallibleOpFailure> fallibleOp() {
if (true) {
return ok(FallibleOpSuccess());
} else {
return err(FallibleOpFailure());
}
}
final result = fallibleOp();
switch(result.type) {
case ResultType.ok:
print('Success with value: ${result.unwrap()}');
break;
case ResultType.err:
print('Failure with error: ${result.unwrapErr()};');
break;
}