Skip to content

Commit ac58a5f

Browse files
authored
Better doc for SystemName (#11084)
Compared to [current documentation](https://docs.rs/bevy/latest/bevy/ecs/system/struct.SystemName.html) it is now immediately clear that it is `SystemParam` readily available to user, and not just some accidentally exposed internal data type.
1 parent 13feac6 commit ac58a5f

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,10 +1287,32 @@ unsafe impl SystemParam for SystemChangeTick {
12871287
}
12881288
}
12891289

1290-
/// Name of the system that corresponds to this [`crate::system::SystemState`].
1290+
/// [`SystemParam`] that returns the name of the system which it is used in.
12911291
///
1292-
/// This is not a reliable identifier, it is more so useful for debugging
1293-
/// purposes of finding where a system parameter is being used incorrectly.
1292+
/// This is not a reliable identifier, it is more so useful for debugging or logging.
1293+
///
1294+
/// # Examples
1295+
///
1296+
/// ```
1297+
/// # use bevy_ecs::system::SystemName;
1298+
/// # use bevy_ecs::system::SystemParam;
1299+
///
1300+
/// #[derive(SystemParam)]
1301+
/// struct Logger<'s> {
1302+
/// system_name: SystemName<'s>,
1303+
/// }
1304+
///
1305+
/// impl<'s> Logger<'s> {
1306+
/// fn log(&mut self, message: &str) {
1307+
/// eprintln!("{}: {}", self.system_name, message);
1308+
/// }
1309+
/// }
1310+
///
1311+
/// fn system1(mut logger: Logger) {
1312+
/// // Prints: "crate_name::mod_name::system1: Hello".
1313+
/// logger.log("Hello");
1314+
/// }
1315+
/// ```
12941316
#[derive(Debug)]
12951317
pub struct SystemName<'s>(&'s str);
12961318

0 commit comments

Comments
 (0)