Skip to content

Commit

Permalink
Remove Anyhow::Result in system_piping.rs example (bevyengine#7657)
Browse files Browse the repository at this point in the history
# Objective

Fixes: bevyengine#7610 

## Solution

- Return a specific error type
  • Loading branch information
foxzool authored and myreprise1 committed Feb 15, 2023
1 parent 7dab351 commit a7877af
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/ecs/system_piping.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Illustrates how to make a single system from multiple functions running in sequence,
//! passing the output of the first into the input of the next.
use anyhow::Result;
use bevy::prelude::*;
use std::num::ParseIntError;

use bevy::log::LogPlugin;
use bevy::utils::tracing::Level;
Expand Down Expand Up @@ -31,20 +31,20 @@ struct Message(String);
struct OptionalWarning(Result<(), String>);

// This system produces a Result<usize> output by trying to parse the Message resource.
fn parse_message_system(message: Res<Message>) -> Result<usize> {
Ok(message.parse::<usize>()?)
fn parse_message_system(message: Res<Message>) -> Result<usize, ParseIntError> {
message.parse::<usize>()
}

// This system produces a Result<()> output by trying to parse the Message resource.
fn parse_error_message_system(message: Res<Message>) -> Result<()> {
fn parse_error_message_system(message: Res<Message>) -> Result<(), ParseIntError> {
message.parse::<usize>()?;
Ok(())
}

// This system takes a Result<usize> input and either prints the parsed value or the error message
// Try changing the Message resource to something that isn't an integer. You should see the error
// message printed.
fn handler_system(In(result): In<Result<usize>>) {
fn handler_system(In(result): In<Result<usize, ParseIntError>>) {
match result {
Ok(value) => println!("parsed message: {value}"),
Err(err) => println!("encountered an error: {err:?}"),
Expand Down

0 comments on commit a7877af

Please sign in to comment.