rust_core 0.5.0-dev2 rust_core: ^0.5.0-dev2 copied to clipboard
Implementation of Rust's core library in Dart. Includes types like Result, Option, Cells, Slices, Array, and extensive methods/extensions.
import 'package:rust_core/result.dart';
void main() {
usingTheEarlyReturnKey();
usingRegularPatternMatching();
}
Result<int, String> usingTheEarlyReturnKey() => Result(($) {
// Early Return Key
// Will return here with 'Err("error")'
int x = willAlwaysReturnErr()[$].toInt();
return Ok(x);
});
Result<int, String> usingRegularPatternMatching() {
int x;
switch (willAlwaysReturnErr()) {
case Err(:final err):
return Err(err);
case Ok(:final ok):
x = ok.toInt();
}
return Ok(x);
}
Result<double, String> willAlwaysReturnErr() => Err("error");