Remove Anyhow::Result in system_piping.rs example (#7657)
# Objective Fixes: #7610 ## Solution - Return a specific error type
This commit is contained in:
parent
9dadde06cb
commit
2efc0293ed
@ -1,8 +1,8 @@
|
|||||||
//! Illustrates how to make a single system from multiple functions running in sequence,
|
//! 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.
|
//! passing the output of the first into the input of the next.
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
use bevy::log::LogPlugin;
|
use bevy::log::LogPlugin;
|
||||||
use bevy::utils::tracing::Level;
|
use bevy::utils::tracing::Level;
|
||||||
@ -31,12 +31,12 @@ struct Message(String);
|
|||||||
struct OptionalWarning(Result<(), String>);
|
struct OptionalWarning(Result<(), String>);
|
||||||
|
|
||||||
// This system produces a Result<usize> output by trying to parse the Message resource.
|
// This system produces a Result<usize> output by trying to parse the Message resource.
|
||||||
fn parse_message_system(message: Res<Message>) -> Result<usize> {
|
fn parse_message_system(message: Res<Message>) -> Result<usize, ParseIntError> {
|
||||||
Ok(message.parse::<usize>()?)
|
message.parse::<usize>()
|
||||||
}
|
}
|
||||||
|
|
||||||
// This system produces a Result<()> output by trying to parse the Message resource.
|
// 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>()?;
|
message.parse::<usize>()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ fn parse_error_message_system(message: Res<Message>) -> Result<()> {
|
|||||||
// This system takes a Result<usize> input and either prints the parsed value or the error message
|
// 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
|
// Try changing the Message resource to something that isn't an integer. You should see the error
|
||||||
// message printed.
|
// message printed.
|
||||||
fn handler_system(In(result): In<Result<usize>>) {
|
fn handler_system(In(result): In<Result<usize, ParseIntError>>) {
|
||||||
match result {
|
match result {
|
||||||
Ok(value) => println!("parsed message: {value}"),
|
Ok(value) => println!("parsed message: {value}"),
|
||||||
Err(err) => println!("encountered an error: {err:?}"),
|
Err(err) => println!("encountered an error: {err:?}"),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user