Skip to content

Commit

Permalink
chore: Upgrade rust version
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Dec 3, 2024
1 parent 7f67f07 commit 47afd28
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void main() {
Result<String> order(String user, int orderNumber) {
final result = makeFood(orderNumber).context("Could not order for $user.");
if(result case Ok(:final ok)) {
return Ok("Order of $ok is complete for $user");
if(result case Ok(o:final order)) {
return Ok("Order of $order is complete for $user");
}
return result;
}
Expand Down Expand Up @@ -77,8 +77,8 @@ void main() {
Result<String, String> order(String user, int orderNumber) {
final result = makeFood(orderNumber);
if(result case Ok(:final ok)) {
return Ok("Order of $ok is complete for $user");
if(result case Ok(o:final order)) {
return Ok("Order of $order is complete for $user");
}
Logging.w("Could not order for $user.");
return result;
Expand Down
4 changes: 2 additions & 2 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ void main() {
Result<String> order(String user, int orderNumber) {
final result =
makeFood(orderNumber).context("Could not order for user: $user.");
if (result case Ok(:final ok)) {
return Ok("Order of $ok is complete for $user");
if (result case Ok(o:final order)) {
return Ok("Order of $order is complete for $user");
}
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions example/working_with_anyhow_errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:anyhow/anyhow.dart';

void main() {
Result err = bail("This is a single error");
if (err case Ok(:final ok)) {
print(ok);
if (err case Ok(:final okay)) {
print(okay);
}
print(err.unwrapErr());
err = err.context("This is context for the error");
Expand Down
20 changes: 10 additions & 10 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ extension AnyhowResultExtension<S> on Result<S> {
switch (this) {
case Ok():
return this;
case Err(:final err):
case Err(:final error):
assert(context is! Error, _isAlreadyErrorAssertionMessage);
if (Error.hasStackTrace) {
return Err(
Error._withStackTrace(context, StackTrace.current, parent: err));
Error._withStackTrace(context, StackTrace.current, parent: error));
}
return Err(Error(context, parent: err));
return Err(Error(context, parent: error));
}
}

Expand All @@ -28,14 +28,14 @@ extension AnyhowResultExtension<S> on Result<S> {
switch (this) {
case Ok():
return this;
case Err(:final err):
case Err(:final error):
final context = fn();
assert(context is! Error, _isAlreadyErrorAssertionMessage);
if (Error.hasStackTrace) {
return Err(
Error._withStackTrace(context, StackTrace.current, parent: err));
Error._withStackTrace(context, StackTrace.current, parent: error));
}
return Err(Error(context, parent: err));
return Err(Error(context, parent: error));
}
}
}
Expand All @@ -58,9 +58,9 @@ extension AnyhowErrExtension<S> on Err<S> {
assert(context is! Error, _isAlreadyErrorAssertionMessage);
if (Error.hasStackTrace) {
return Err(
Error._withStackTrace(context, StackTrace.current, parent: err));
Error._withStackTrace(context, StackTrace.current, parent: error));
}
return Err(Error(context, parent: err));
return Err(Error(context, parent: error));
}

/// Lazily calls the function if the [Result] is an [Err] and returns an [Error] with the additional context.
Expand All @@ -70,9 +70,9 @@ extension AnyhowErrExtension<S> on Err<S> {
assert(context is! Error, _isAlreadyErrorAssertionMessage);
if (Error.hasStackTrace) {
return Err(
Error._withStackTrace(context, StackTrace.current, parent: err));
Error._withStackTrace(context, StackTrace.current, parent: error));
}
return Err(Error(context, parent: err));
return Err(Error(context, parent: error));
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
sdk: ">=3.3.0 <4.0.0"

dependencies:
rust: ^2.0.0
rust: ^2.0.1

dev_dependencies:
lints: ^5.0.0
Expand Down
4 changes: 2 additions & 2 deletions test/result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void main() {
test("context", () {
final result = bail(1).context("bing bong").context("bong bing");
List<Object> causes = [];
for (final (index, cause) in result.err.chain().indexed) {
for (final (index, cause) in result.error.chain().indexed) {
if (index == 2) {
causes.add(cause.downcast<int>().unwrap());
} else {
Expand All @@ -343,7 +343,7 @@ void main() {
final result =
bail(1).withContext(() => "bing bong").withContext(() => "bong bing");
List<Object> causes = [];
for (final (index, cause) in result.err.chain().indexed) {
for (final (index, cause) in result.error.chain().indexed) {
if (index == 2) {
causes.add(cause.downcast<int>().unwrap());
} else {
Expand Down

0 comments on commit 47afd28

Please sign in to comment.