Skip to content

Commit

Permalink
Resolve Clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wiggleforlife committed Dec 7, 2024
1 parent 77ee0ec commit 70609d2
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 60 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_plugin/src/commands/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub(crate) fn command_execution_plugin(app: &mut App) {
);
}

fn execute_commands(world: &mut World, mut reader: Local<EventCursor<ExecuteCommandEvent>>) {
let events = clone_events(world, &mut reader);
fn execute_commands(world: &mut World, mut cursor: Local<EventCursor<ExecuteCommandEvent>>) {
let events = clone_events(world, &mut cursor);
for event in events {
let Some(mut command) = clone_command(world, &event) else {
continue;
Expand All @@ -30,10 +30,10 @@ fn execute_commands(world: &mut World, mut reader: Local<EventCursor<ExecuteComm

fn clone_events(
world: &World,
reader: &mut EventCursor<ExecuteCommandEvent>,
cursor: &mut EventCursor<ExecuteCommandEvent>,
) -> Vec<ExecuteCommandEvent> {
let events = world.resource::<Events<ExecuteCommandEvent>>();
reader.read(events).cloned().collect()
cursor.read(events).cloned().collect()
}

fn clone_command(
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_plugin/src/dialogue_runner/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct InnerDialogue<'a>(pub(crate) &'a Dialogue);
#[derive(Debug)]
pub struct InnerDialogueMut<'a>(pub(crate) &'a mut Dialogue);

impl<'a> InnerDialogue<'a> {
impl InnerDialogue<'_> {
/// Proxy for [`Dialogue::node_names`].
pub fn node_names(&self) -> impl Iterator<Item = &str> {
self.0.node_names().unwrap()
Expand All @@ -33,7 +33,7 @@ impl<'a> InnerDialogue<'a> {
}
}

impl<'a> InnerDialogueMut<'a> {
impl InnerDialogueMut<'_> {
/// Proxy for [`Dialogue::node_names`].
pub fn node_names(&self) -> impl Iterator<Item = &str> {
self.0.node_names().unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct StringsFileTextProvider {
base_string_table: HashMap<LineId, StringInfo>,
strings_file_handle: Option<Handle<StringsFile>>,
translation_string_table: Option<HashMap<LineId, String>>,
event_reader: Arc<RwLock<EventCursor<AssetEvent<StringsFile>>>>,
event_cursor: Arc<RwLock<EventCursor<AssetEvent<StringsFile>>>>,
}

impl UnderlyingTextProvider for StringsFileTextProvider {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl StringsFileTextProvider {
base_string_table: yarn_project.compilation.string_table.clone(),
strings_file_handle: None,
translation_string_table: None,
event_reader: Default::default(),
event_cursor: Default::default(),
}
}
fn set_language_invalidating_translation(&mut self, language: impl Into<Option<Language>>) {
Expand Down Expand Up @@ -158,8 +158,8 @@ impl TextProvider for StringsFileTextProvider {
}
let asset_events = world.resource::<Events<AssetEvent<StringsFile>>>();
let strings_file_has_changed = || {
let mut reader = self.event_reader.write().unwrap();
reader.read(asset_events).any(|event| match event {
let mut cursor = self.event_cursor.write().unwrap();
cursor.read(asset_events).any(|event| match event {
AssetEvent::Modified { id } => *id == handle.id(),
_ => false,
})
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_plugin/src/localization/strings_file/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::prelude::*;
use anyhow::{anyhow, bail};
use bevy::asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext};
use bevy::asset::{io::Reader, AssetLoader, LoadContext};
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy::utils::HashMap;
Expand All @@ -27,7 +27,7 @@ impl AssetLoader for StringsFileAssetLoader {
&self,
reader: &mut dyn Reader,
_settings: &(),
load_context: &mut LoadContext<'_>,
_load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/plugin/yarn_file_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::plugin::AssetRoot;
use crate::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android")))]
use anyhow::ensure;
use bevy::{prelude::*, reflect::TypePath};
use bevy::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android")))]
use glob::glob;
use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/yarn_file_asset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use bevy::asset::{io::Reader, AsyncReadExt};
use bevy::asset::io::Reader;
use bevy::prelude::*;

use bevy::asset::{AssetLoader, LoadContext};
Expand Down
54 changes: 27 additions & 27 deletions crates/bevy_plugin/tests/utils/assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use bevy_yarnspinner::events::*;

#[derive(Debug, Default)]
pub struct EventAsserter {
pub present_line_reader: EventCursor<PresentLineEvent>,
pub present_options_reader: EventCursor<PresentOptionsEvent>,
pub dialogue_start_reader: EventCursor<DialogueStartEvent>,
pub dialogue_complete_reader: EventCursor<DialogueCompleteEvent>,
pub node_start_reader: EventCursor<NodeStartEvent>,
pub node_complete_reader: EventCursor<NodeCompleteEvent>,
pub line_hints_reader: EventCursor<LineHintsEvent>,
pub execute_command_reader: EventCursor<ExecuteCommandEvent>,
pub present_line_cursor: EventCursor<PresentLineEvent>,
pub present_options_cursor: EventCursor<PresentOptionsEvent>,
pub dialogue_start_cursor: EventCursor<DialogueStartEvent>,
pub dialogue_complete_cursor: EventCursor<DialogueCompleteEvent>,
pub node_start_cursor: EventCursor<NodeStartEvent>,
pub node_complete_cursor: EventCursor<NodeCompleteEvent>,
pub line_hints_cursor: EventCursor<LineHintsEvent>,
pub execute_command_cursor: EventCursor<ExecuteCommandEvent>,
}

impl EventAsserter {
Expand All @@ -20,50 +20,50 @@ impl EventAsserter {
}

pub fn clear_events(&mut self, app: &mut App) {
self.present_line_reader
self.present_line_cursor
.clear(app.world().resource::<Events<PresentLineEvent>>());
self.present_options_reader
self.present_options_cursor
.clear(app.world().resource::<Events<PresentOptionsEvent>>());
self.dialogue_start_reader
self.dialogue_start_cursor
.clear(app.world().resource::<Events<DialogueStartEvent>>());
self.dialogue_complete_reader
self.dialogue_complete_cursor
.clear(app.world().resource::<Events<DialogueCompleteEvent>>());
self.node_start_reader
self.node_start_cursor
.clear(app.world().resource::<Events<NodeStartEvent>>());
self.node_complete_reader
self.node_complete_cursor
.clear(app.world().resource::<Events<NodeCompleteEvent>>());
self.line_hints_reader
self.line_hints_cursor
.clear(app.world().resource::<Events<LineHintsEvent>>());
self.execute_command_reader
self.execute_command_cursor
.clear(app.world().resource::<Events<ExecuteCommandEvent>>());
}
}

#[macro_export]
macro_rules! get_reader {
macro_rules! get_cursor {
($asserter:ident, PresentLineEvent) => {
&mut $asserter.present_line_reader
&mut $asserter.present_line_cursor
};
($asserter:ident, PresentOptionsEvent) => {
&mut $asserter.present_options_reader
&mut $asserter.present_options_cursor
};
($asserter:ident, DialogueStartEvent) => {
&mut $asserter.dialogue_start_reader
&mut $asserter.dialogue_start_cursor
};
($asserter:ident, DialogueCompleteEvent) => {
&mut $asserter.dialogue_complete_reader
&mut $asserter.dialogue_complete_cursor
};
($asserter:ident, NodeStartEvent) => {
&mut $asserter.node_start_reader
&mut $asserter.node_start_cursor
};
($asserter:ident, NodeCompleteEvent) => {
&mut $asserter.node_complete_reader
&mut $asserter.node_complete_cursor
};
($asserter:ident, LineHintsEvent) => {
&mut $asserter.line_hints_reader
&mut $asserter.line_hints_cursor
};
($asserter:ident, ExecuteCommandEvent) => {
&mut $asserter.execute_command_reader
&mut $asserter.execute_command_cursor
};
}

Expand All @@ -79,8 +79,8 @@ macro_rules! assert_events {
};
($asserter:ident, $app:ident contains $event:ident (n = $num:expr) $(with $pred:expr)?) => {
let events = $app.world().resource::<bevy::prelude::Events<$event>>();
let reader = $crate::get_reader!($asserter, $event);
let events: Vec<&$event> = reader.read(&events).collect();
let cursor = $crate::get_cursor!($asserter, $event);
let events: Vec<&$event> = cursor.read(&events).collect();
assert_eq!($num, events.len(), "Expected {} events of type {}, but found {}: {events:#?}", stringify!($num), stringify!($event), events.len());
$(
{
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/listeners/compiler_listener/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use antlr_rust::token::Token;
use yarnspinner_core::prelude::OpCode;
use yarnspinner_core::prelude::*;

impl<'input> CompilerListener<'input> {
impl CompilerListener<'_> {
/// Creates a new instruction, and appends it to a node in the [`Program`].
pub(crate) fn emit(&mut self, emit: Emit) {
let instruction = Instruction {
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/src/listeners/error_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ impl<'input, T: Recognizer<'input>> ErrorListener<'input, T> for ParserErrorList
}
}

impl<'input> ParseTreeListener<'input, YarnSpinnerParserContextType> for ParserErrorListener {}
impl<'input> YarnSpinnerParserListener<'input> for ParserErrorListener {}
impl ParseTreeListener<'_, YarnSpinnerParserContextType> for ParserErrorListener {}
impl YarnSpinnerParserListener<'_> for ParserErrorListener {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) struct LastLineBeforeOptionsVisitor {
_dummy: (),
}

impl<'input> ParseTreeVisitorCompat<'input> for LastLineBeforeOptionsVisitor {
impl ParseTreeVisitorCompat<'_> for LastLineBeforeOptionsVisitor {
type Node = YarnSpinnerParserContextType;
type Return = ();

Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/visitors/node_tracking_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl NodeTrackingVisitor {
}
}

impl<'input> ParseTreeVisitorCompat<'input> for NodeTrackingVisitor {
impl ParseTreeVisitorCompat<'_> for NodeTrackingVisitor {
type Node = YarnSpinnerParserContextType;
type Return = Option<String>;

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/yarn_fn/parameter_wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
phantom_data: PhantomData<T>,
}

impl<'res, T> YarnFnParam for ResRef<'res, T>
impl<T> YarnFnParam for ResRef<'_, T>
where
T: TryFrom<YarnValue> + 'static,
<T as TryFrom<YarnValue>>::Error: Display,
Expand Down Expand Up @@ -145,7 +145,7 @@ where
phantom_data: PhantomData<T>,
}

impl<'res, T, U> YarnFnParam for ResRefBorrow<'res, T, U>
impl<T, U> YarnFnParam for ResRefBorrow<'_, T, U>
where
T: TryFrom<YarnValue> + 'static,
<T as TryFrom<YarnValue>>::Error: Display,
Expand Down
8 changes: 4 additions & 4 deletions crates/example_dialogue_view/src/option_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fn create_options(
mut options_node: Query<(Entity, &mut Node, &mut Visibility), With<OptionsNode>>,
mut root_visibility: Query<&mut Visibility, (With<UiRootNode>, Without<OptionsNode>)>,
) {
let (entity, mut style, mut visibility) = options_node.single_mut();
style.display = Display::Flex;
let (entity, mut node, mut visibility) = options_node.single_mut();
node.display = Display::Flex;
*visibility = Visibility::Hidden;
if children.iter_descendants(entity).next().is_none() {
*root_visibility.single_mut() = Visibility::Inherited;
Expand Down Expand Up @@ -149,9 +149,9 @@ fn despawn_options(
has_selected_option_event.clear();
dialogue_complete_event.clear();
commands.remove_resource::<OptionSelection>();
let (entity, mut style, mut visibility) = options_node.single_mut();
let (entity, mut node, mut visibility) = options_node.single_mut();
commands.entity(entity).despawn_descendants();
style.display = Display::None;
node.display = Display::None;
*visibility = Visibility::Hidden;
*dialogue_node_text.single_mut() = Text::default();
*root_visibility.single_mut() = Visibility::Hidden;
Expand Down
6 changes: 3 additions & 3 deletions crates/example_dialogue_view/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn setup(mut commands: Commands) {
.with_children(|parent| {
parent.spawn((
fmt_name("name"),
Text::new(String::new()),
Text::default(),
text_style::name(),
Node {
margin: UiRect {
Expand Down Expand Up @@ -92,7 +92,7 @@ fn setup(mut commands: Commands) {
// Dialog itself
parent.spawn((
fmt_name("text"),
Text(String::new()),
Text::default(),
text_style::standard(),
style::standard(),
DialogueNode,
Expand Down Expand Up @@ -192,7 +192,7 @@ where
parent
.spawn((
fmt_name("option text"),
Text(String::new()),
Text::default(),
style::options(),
Label,
))
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_yarnspinner/src/bin/access_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
}

fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2d::default());
commands.spawn(Camera2d);
}

fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_yarnspinner/src/bin/custom_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
}

fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2d::default());
commands.spawn(Camera2d);
}

fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_yarnspinner/src/bin/custom_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
}

fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2d::default());
commands.spawn(Camera2d);
}

fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_yarnspinner/src/bin/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
}

fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2d::default());
commands.spawn(Camera2d);
}

fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/yarnspinner_without_bevy/src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a> LineView<'a> {
}
}

impl<'a> Widget for LineView<'a> {
impl Widget for LineView<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
Paragraph::new(self.line.text_without_character_name().as_str())
.style(self.style)
Expand Down

0 comments on commit 70609d2

Please sign in to comment.