bevy/crates/bevy_ecs/examples/resources.rs
Cyrill Schenkel 8570af1d96
Add print_stdout and print_stderr lints (#17446) (#18233)
# Objective

- Prevent usage of `println!`, `eprintln!` and the like because they
require `std`
- Fixes #17446

## Solution

- Enable the `print_stdout` and `print_stderr` clippy lints
- Replace all `println!` and `eprintln!` occurrences with `log::*` where
applicable or alternatively ignore the warnings

## Testing

- Run `cargo clippy --workspace` to ensure that there are no warnings
relating to printing to `stdout` or `stderr`
2025-03-11 19:35:48 +00:00

49 lines
1.2 KiB
Rust

//! In this example we add a counter resource and increase its value in one system,
//! while a different system prints the current count to the console.
#![expect(
clippy::std_instead_of_core,
clippy::print_stdout,
reason = "Examples should not follow this lint"
)]
use bevy_ecs::prelude::*;
use rand::Rng;
use std::ops::Deref;
fn main() {
// Create a world
let mut world = World::new();
// Add the counter resource
world.insert_resource(Counter { value: 0 });
// Create a schedule
let mut schedule = Schedule::default();
// Add systems to increase the counter and to print out the current value
schedule.add_systems((increase_counter, print_counter).chain());
for iteration in 1..=10 {
println!("Simulating frame {iteration}/10");
schedule.run(&mut world);
}
}
// Counter resource to be increased and read by systems
#[derive(Debug, Resource)]
struct Counter {
pub value: i32,
}
fn increase_counter(mut counter: ResMut<Counter>) {
if rand::thread_rng().gen_bool(0.5) {
counter.value += 1;
println!(" Increased counter value");
}
}
fn print_counter(counter: Res<Counter>) {
println!(" {:?}", counter.deref());
}