Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Unified Diff: lib/src/result/error.dart

Issue 2996143002: Add methods to Result. Bump version to 2.0 and remove deprecated features. (Closed)
Patch Set: Address comments, run dartfmt on tests too. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/result/capture_transformer.dart ('k') | lib/src/result/future.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/result/error.dart
diff --git a/lib/src/result/error.dart b/lib/src/result/error.dart
index b6d585937f520f736cd77d322945bb6796722649..45e06a20f53e0c72fe517ae78b2669caf2e7e105 100644
--- a/lib/src/result/error.dart
+++ b/lib/src/result/error.dart
@@ -4,18 +4,21 @@
import 'dart:async';
-import '../result.dart';
+import 'result.dart';
import 'value.dart';
/// A result representing a thrown error.
-class ErrorResult<T> implements Result<T> {
+class ErrorResult implements Result<Null> {
+ /// The error object that was thrown.
final error;
+
+ /// The stack trace corresponding to where [error] was thrown.
final StackTrace stackTrace;
bool get isValue => false;
bool get isError => true;
- ValueResult<T> get asValue => null;
- ErrorResult<T> get asError => this;
+ ValueResult<Null> get asValue => null;
+ ErrorResult get asError => this;
ErrorResult(this.error, this.stackTrace);
@@ -27,7 +30,7 @@ class ErrorResult<T> implements Result<T> {
sink.addError(error, stackTrace);
}
- Future<T> get asFuture => new Future.error(error, stackTrace);
+ Future<Null> get asFuture => new Future<Null>.error(error, stackTrace);
/// Calls an error handler with the error and stacktrace.
///
@@ -42,4 +45,12 @@ class ErrorResult<T> implements Result<T> {
errorHandler(error);
}
}
+
+ int get hashCode => error.hashCode ^ stackTrace.hashCode ^ 0x1d61823f;
+
+ /// This is equal only to an error result with equal [error] and [stackTrace].
+ bool operator ==(Object other) =>
+ other is ErrorResult &&
+ error == other.error &&
+ stackTrace == other.stackTrace;
}
« no previous file with comments | « lib/src/result/capture_transformer.dart ('k') | lib/src/result/future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698