mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 06:00:20 +00:00
style: simplify string formatting for readability (#15033)
# Objective The goal of this change is to improve code readability and maintainability.
This commit is contained in:
parent
4ac2a63556
commit
ec728c31c1
12 changed files with 27 additions and 37 deletions
|
@ -351,7 +351,7 @@ fn setup(
|
|||
/// Writes a simple menu item that can be on or off.
|
||||
fn draw_selectable_menu_item(ui: &mut String, label: &str, shortcut: char, enabled: bool) {
|
||||
let star = if enabled { "*" } else { "" };
|
||||
let _ = writeln!(*ui, "({}) {}{}{}", shortcut, star, label, star);
|
||||
let _ = writeln!(*ui, "({shortcut}) {star}{label}{star}");
|
||||
}
|
||||
|
||||
/// Creates a colorful test pattern
|
||||
|
|
|
@ -459,9 +459,9 @@ impl Display for SelectedSectionColorGradingOption {
|
|||
impl Display for SelectedColorGradingOption {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
SelectedColorGradingOption::Global(option) => write!(f, "\"{}\"", option),
|
||||
SelectedColorGradingOption::Global(option) => write!(f, "\"{option}\""),
|
||||
SelectedColorGradingOption::Section(section, option) => {
|
||||
write!(f, "\"{}\" for \"{}\"", option, section)
|
||||
write!(f, "\"{option}\" for \"{section}\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -633,7 +633,7 @@ fn update_ui_state(
|
|||
|
||||
/// Creates the help text at the top left of the window.
|
||||
fn create_help_text(currently_selected_option: &SelectedColorGradingOption) -> String {
|
||||
format!("Press Left/Right to adjust {}", currently_selected_option)
|
||||
format!("Press Left/Right to adjust {currently_selected_option}")
|
||||
}
|
||||
|
||||
/// Processes keyboard input to change the value of the currently-selected color
|
||||
|
|
|
@ -351,12 +351,11 @@ impl AppStatus {
|
|||
|
||||
Text::from_section(
|
||||
format!(
|
||||
"{}\n{}\n{}\n{}\n{}",
|
||||
CLICK_TO_MOVE_HELP_TEXT,
|
||||
voxels_help_text,
|
||||
irradiance_volume_help_text,
|
||||
rotation_help_text,
|
||||
switch_mesh_help_text
|
||||
"{CLICK_TO_MOVE_HELP_TEXT}
|
||||
{voxels_help_text}
|
||||
{irradiance_volume_help_text}
|
||||
{rotation_help_text}
|
||||
{switch_mesh_help_text}"
|
||||
),
|
||||
TextStyle::default(),
|
||||
)
|
||||
|
|
|
@ -533,7 +533,7 @@ fn update(
|
|||
// Finally saving image to file, this heavy blocking operation is kept here
|
||||
// for example simplicity, but in real app you should move it to a separate task
|
||||
if let Err(e) = img.save(image_path) {
|
||||
panic!("Failed to save image: {}", e);
|
||||
panic!("Failed to save image: {e}");
|
||||
};
|
||||
}
|
||||
if scene_controller.single_image {
|
||||
|
|
|
@ -69,10 +69,7 @@ fn setup(world: &mut World) {
|
|||
.on_add(|mut world, entity, component_id| {
|
||||
// You can access component data from within the hook
|
||||
let value = world.get::<MyComponent>(entity).unwrap().0;
|
||||
println!(
|
||||
"Component: {:?} added to: {:?} with value {:?}",
|
||||
component_id, entity, value
|
||||
);
|
||||
println!("Component: {component_id:?} added to: {entity:?} with value {value:?}");
|
||||
// Or access resources
|
||||
world
|
||||
.resource_mut::<MyComponentIndex>()
|
||||
|
@ -96,10 +93,7 @@ fn setup(world: &mut World) {
|
|||
// since it runs before the component is removed you can still access the component data
|
||||
.on_remove(|mut world, entity, component_id| {
|
||||
let value = world.get::<MyComponent>(entity).unwrap().0;
|
||||
println!(
|
||||
"Component: {:?} removed from: {:?} with value {:?}",
|
||||
component_id, entity, value
|
||||
);
|
||||
println!("Component: {component_id:?} removed from: {entity:?} with value {value:?}");
|
||||
// You can also issue commands through `.commands()`
|
||||
world.commands().entity(entity).despawn();
|
||||
});
|
||||
|
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
let mut component_names = HashMap::<String, ComponentId>::new();
|
||||
let mut component_info = HashMap::<ComponentId, ComponentInfo>::new();
|
||||
|
||||
println!("{}", PROMPT);
|
||||
println!("{PROMPT}");
|
||||
loop {
|
||||
print!("\n> ");
|
||||
let _ = std::io::stdout().flush();
|
||||
|
@ -64,10 +64,10 @@ fn main() {
|
|||
|
||||
let Some((first, rest)) = line.trim().split_once(|c: char| c.is_whitespace()) else {
|
||||
match &line.chars().next() {
|
||||
Some('c') => println!("{}", COMPONENT_PROMPT),
|
||||
Some('s') => println!("{}", ENTITY_PROMPT),
|
||||
Some('q') => println!("{}", QUERY_PROMPT),
|
||||
_ => println!("{}", PROMPT),
|
||||
Some('c') => println!("{COMPONENT_PROMPT}"),
|
||||
Some('s') => println!("{ENTITY_PROMPT}"),
|
||||
Some('q') => println!("{QUERY_PROMPT}"),
|
||||
_ => println!("{PROMPT}"),
|
||||
}
|
||||
continue;
|
||||
};
|
||||
|
@ -112,7 +112,7 @@ fn main() {
|
|||
|
||||
// Get the id for the component with the given name
|
||||
let Some(&id) = component_names.get(name) else {
|
||||
println!("Component {} does not exist", name);
|
||||
println!("Component {name} does not exist");
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -245,7 +245,7 @@ fn parse_term<Q: QueryData>(
|
|||
};
|
||||
|
||||
if !matched {
|
||||
println!("Unable to find component: {}", str);
|
||||
println!("Unable to find component: {str}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ fn send_events(mut events: EventWriter<DebugEvent>, frame_count: Res<FrameCount>
|
|||
/// Note that some events will be printed twice, because they were sent twice.
|
||||
fn debug_events(mut events: EventReader<DebugEvent>) {
|
||||
for event in events.read() {
|
||||
println!("{:?}", event);
|
||||
println!("{event:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ fn build_ui(
|
|||
for label in schedule_order {
|
||||
let schedule = schedules.get(*label).unwrap();
|
||||
text_sections.push(TextSection::new(
|
||||
format!("{:?}\n", label),
|
||||
format!("{label:?}\n"),
|
||||
TextStyle {
|
||||
font: asset_server.load(FONT_BOLD),
|
||||
color: FONT_COLOR,
|
||||
|
|
|
@ -73,8 +73,8 @@ fn setup(mut commands: Commands) {
|
|||
R: Remove the last control point\n\
|
||||
S: Cycle the spline construction being used\n\
|
||||
C: Toggle cyclic curve construction";
|
||||
let spline_mode_text = format!("Spline: {}", spline_mode);
|
||||
let cycling_mode_text = format!("{}", cycling_mode);
|
||||
let spline_mode_text = format!("Spline: {spline_mode}");
|
||||
let cycling_mode_text = format!("{cycling_mode}");
|
||||
let style = TextStyle::default();
|
||||
|
||||
commands
|
||||
|
|
|
@ -87,8 +87,7 @@ impl FromStr for Layout {
|
|||
"cube" => Ok(Self::Cube),
|
||||
"sphere" => Ok(Self::Sphere),
|
||||
_ => Err(format!(
|
||||
"Unknown layout value: '{}', valid options: 'cube', 'sphere'",
|
||||
s
|
||||
"Unknown layout value: '{s}', valid options: 'cube', 'sphere'"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ fn runner(mut app: App) -> AppExit {
|
|||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines() {
|
||||
if let Err(err) = line {
|
||||
println!("read err: {:#}", err);
|
||||
println!("read err: {err:#}");
|
||||
break;
|
||||
}
|
||||
match line.unwrap().as_str() {
|
||||
|
|
|
@ -34,8 +34,7 @@ fn main() {
|
|||
assert_eq!(
|
||||
main_app_ambiguities.total(),
|
||||
0,
|
||||
"Main app has unexpected ambiguities among the following schedules: \n{:#?}.",
|
||||
main_app_ambiguities,
|
||||
"Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
|
||||
);
|
||||
|
||||
// RenderApp is not checked here, because it is not within the App at this point.
|
||||
|
@ -43,8 +42,7 @@ fn main() {
|
|||
assert_eq!(
|
||||
render_extract_ambiguities.total(),
|
||||
0,
|
||||
"RenderExtract app has unexpected ambiguities among the following schedules: \n{:#?}",
|
||||
render_extract_ambiguities,
|
||||
"RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue