rust_core 0.5.0-dev1 rust_core: ^0.5.0-dev1 copied to clipboard
Implementation of Rust's core library in Dart where it makes sense. 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");