Skip to content
pubscout

option_result

3.3.0, released 9 months ago by an unverified publisher

Rust-like Option and Result types for Dart with exhaustive pattern matching support.

WASM-ready
$ flutter pub add option_result
Source repository

What it does

A lightweight Dart library that brings Rust's Option and Result types, providing methods for composition and supporting Dart 3's exhaustive pattern matching for safe error and absence handling.

AI-written summary of version 3.3.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want Rust-style error handling with Result types instead of try/catch blocks.
  • You want to handle the presence or absence of values composably using Option types.
  • You want to use Dart 3 exhaustive pattern matching for error and value branching.

Skip it when

  • You prefer idiomatic Dart null-safety and standard exceptions.
  • Your team is not familiar with Rust-like monads or functional error handling.

Strengths

  • Brings Rust-like Option and Result semantics and combinators to Dart.
  • Supports Dart 3 exhaustive pattern matching.
  • Supports const factory constructors and immutability for better performance.

Weaknesses

  • Requires adopting a non-standard error handling paradigm in Dart.
  • None/Err propagation requires explicit helper blocks like catchOption/catchResult.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
Option<int> divideBy2(int i) => switch (i) {
  0 => None(),
  _ => Some(i ~/ 2)
};

Option<int> a = Some(10);
Option<int> b = a.andThen(divideBy2);

Alternatives

Packages that do the same job and could replace option_result.

  • result_type

    A Result type representing success or failure in Dart

  • oxidized

    Rust‑like Option and Result types for safer Dart code.

  • result_dart

    Kotlin and Swift inspired Result class for error handling in Dart and Flutter.

  • rust_core

    A pure Dart implementation of Rust patterns like Result, Option, Cell, Slice, and Array.