Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy fixes #3718

Closed
wants to merge 12 commits into from
24 changes: 12 additions & 12 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct SubApp {

impl Default for App {
fn default() -> Self {
let mut app = App::empty();
let mut app = Self::empty();
#[cfg(feature = "bevy_reflect")]
app.init_resource::<bevy_reflect::TypeRegistryArc>();

Expand All @@ -85,14 +85,14 @@ impl Default for App {
impl App {
/// Creates a new [`App`] with some default structure to enable core engine features.
/// This is the preferred constructor for most use cases.
pub fn new() -> App {
App::default()
pub fn new() -> Self {
Self::default()
}

/// Creates a new empty [`App`] with minimal default configuration.
///
/// This constructor should be used if you wish to provide a custom schedule, exit handling, cleanup, etc.
pub fn empty() -> App {
pub fn empty() -> Self {
Self {
world: Default::default(),
schedule: Default::default(),
Expand Down Expand Up @@ -127,7 +127,7 @@ impl App {
#[cfg(feature = "trace")]
let _bevy_app_run_guard = bevy_app_run_span.enter();

let mut app = std::mem::replace(self, App::empty());
let mut app = std::mem::replace(self, Self::empty());
let runner = std::mem::replace(&mut app.runner, Box::new(run_once));
(runner)(app);
}
Expand Down Expand Up @@ -746,7 +746,7 @@ impl App {
/// App::new()
/// .set_runner(my_runner);
/// ```
pub fn set_runner(&mut self, run_fn: impl Fn(App) + 'static) -> &mut Self {
pub fn set_runner(&mut self, run_fn: impl Fn(Self) + 'static) -> &mut Self {
self.runner = Box::new(run_fn);
self
}
Expand Down Expand Up @@ -862,8 +862,8 @@ impl App {
pub fn add_sub_app(
&mut self,
label: impl AppLabel,
app: App,
sub_app_runner: impl Fn(&mut World, &mut App) + 'static,
app: Self,
sub_app_runner: impl Fn(&mut World, &mut Self) + 'static,
) -> &mut Self {
self.sub_apps.insert(
Box::new(label),
Expand All @@ -876,7 +876,7 @@ impl App {
}

/// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist.
pub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut App {
pub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut Self {
match self.get_sub_app_mut(label) {
Ok(app) => app,
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
Expand All @@ -885,15 +885,15 @@ impl App {

/// Retrieves a "sub app" inside this [App] with the given label, if it exists. Otherwise returns
/// an [Err] containing the given label.
pub fn get_sub_app_mut(&mut self, label: impl AppLabel) -> Result<&mut App, impl AppLabel> {
pub fn get_sub_app_mut(&mut self, label: impl AppLabel) -> Result<&mut Self, impl AppLabel> {
self.sub_apps
.get_mut((&label) as &dyn AppLabel)
.map(|sub_app| &mut sub_app.app)
.ok_or(label)
}

/// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist.
pub fn sub_app(&self, label: impl AppLabel) -> &App {
pub fn sub_app(&self, label: impl AppLabel) -> &Self {
match self.get_sub_app(label) {
Ok(app) => app,
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
Expand All @@ -902,7 +902,7 @@ impl App {

/// Retrieves a "sub app" inside this [App] with the given label, if it exists. Otherwise returns
/// an [Err] containing the given label.
pub fn get_sub_app(&self, label: impl AppLabel) -> Result<&App, impl AppLabel> {
pub fn get_sub_app(&self, label: impl AppLabel) -> Result<&Self, impl AppLabel> {
self.sub_apps
.get((&label) as &dyn AppLabel)
.map(|sub_app| &sub_app.app)
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_app/src/schedule_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum RunMode {

impl Default for RunMode {
fn default() -> Self {
RunMode::Loop { wait: None }
Self::Loop { wait: None }
}
}

Expand All @@ -39,15 +39,15 @@ pub struct ScheduleRunnerSettings {

impl ScheduleRunnerSettings {
/// [`RunMode::Once`]
pub fn run_once() -> Self {
ScheduleRunnerSettings {
pub const fn run_once() -> Self {
Self {
run_mode: RunMode::Once,
}
}

/// [`RunMode::Loop`]
pub fn run_loop(wait_duration: Duration) -> Self {
ScheduleRunnerSettings {
pub const fn run_loop(wait_duration: Duration) -> Self {
Self {
run_mode: RunMode::Loop {
wait: Some(wait_duration),
},
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl AssetServer {
}

pub fn with_boxed_io(asset_io: Box<dyn AssetIo>, task_pool: TaskPool) -> Self {
AssetServer {
Self {
server: Arc::new(AssetServerInternal {
loaders: Default::default(),
extension_to_loader_index: Default::default(),
Expand Down Expand Up @@ -426,7 +426,7 @@ impl AssetServer {
let asset_sources = self.server.asset_sources.read();
let asset_lifecycles = self.server.asset_lifecycles.read();
for potential_free in potential_frees.drain(..) {
if let Some(&0) = ref_counts.get(&potential_free) {
if ref_counts.get(&potential_free) == Some(&0) {
let type_uuid = match potential_free {
HandleId::Id(type_uuid, _) => Some(type_uuid),
HandleId::AssetPathId(id) => asset_sources
Expand Down
13 changes: 5 additions & 8 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ pub enum AssetEvent<T: Asset> {
impl<T: Asset> Debug for AssetEvent<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AssetEvent::Created { handle } => f
Self::Created { handle } => f
.debug_struct(&format!(
"AssetEvent<{}>::Created",
std::any::type_name::<T>()
))
.field("handle", &handle.id)
.finish(),
AssetEvent::Modified { handle } => f
Self::Modified { handle } => f
.debug_struct(&format!(
"AssetEvent<{}>::Modified",
std::any::type_name::<T>()
))
.field("handle", &handle.id)
.finish(),
AssetEvent::Removed { handle } => f
Self::Removed { handle } => f
.debug_struct(&format!(
"AssetEvent<{}>::Removed",
std::any::type_name::<T>()
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct Assets<T: Asset> {

impl<T: Asset> Assets<T> {
pub(crate) fn new(ref_change_sender: Sender<RefChange>) -> Self {
Assets {
Self {
assets: HashMap::default(),
events: Events::default(),
ref_change_sender,
Expand Down Expand Up @@ -234,10 +234,7 @@ impl<T: Asset> Assets<T> {
self.assets.shrink_to_fit()
}

pub fn asset_event_system(
mut events: EventWriter<AssetEvent<T>>,
mut assets: ResMut<Assets<T>>,
) {
pub fn asset_event_system(mut events: EventWriter<AssetEvent<T>>, mut assets: ResMut<Self>) {
// Check if the events are empty before calling `drain`.
// As `drain` triggers change detection.
if !assets.events.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/filesystem_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Default for FilesystemWatcher {
sender.send(res).expect("Watch event send failure.");
})
.expect("Failed to create filesystem watcher.");
FilesystemWatcher { watcher, receiver }
Self { watcher, receiver }
}
}

Expand Down
34 changes: 17 additions & 17 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ pub enum HandleId {

impl From<AssetPathId> for HandleId {
fn from(value: AssetPathId) -> Self {
HandleId::AssetPathId(value)
Self::AssetPathId(value)
}
}

impl<'a> From<AssetPath<'a>> for HandleId {
fn from(value: AssetPath<'a>) -> Self {
HandleId::AssetPathId(AssetPathId::from(value))
Self::AssetPathId(AssetPathId::from(value))
}
}

impl HandleId {
#[inline]
pub fn random<T: Asset>() -> Self {
HandleId::Id(T::TYPE_UUID, rand::random())
Self::Id(T::TYPE_UUID, rand::random())
}

#[inline]
pub fn default<T: Asset>() -> Self {
HandleId::Id(T::TYPE_UUID, 0)
Self::Id(T::TYPE_UUID, 0)
}

#[inline]
pub const fn new(type_uuid: Uuid, id: u64) -> Self {
HandleId::Id(type_uuid, id)
Self::Id(type_uuid, id)
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@ impl<T: Asset> Handle<T> {

#[inline]
pub fn clone_weak(&self) -> Self {
Handle::weak(self.id)
Self::weak(self.id)
}

pub fn clone_untyped(&self) -> HandleUntyped {
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<T: Asset> Ord for Handle<T> {

impl<T: Asset> Default for Handle<T> {
fn default() -> Self {
Handle::weak(HandleId::default::<T>())
Self::weak(HandleId::default::<T>())
}
}

Expand All @@ -286,8 +286,8 @@ impl<T: Asset> Debug for Handle<T> {
impl<T: Asset> Clone for Handle<T> {
fn clone(&self) -> Self {
match self.handle_type {
HandleType::Strong(ref sender) => Handle::strong(self.id, sender.clone()),
HandleType::Weak => Handle::weak(self.id),
HandleType::Strong(ref sender) => Self::strong(self.id, sender.clone()),
HandleType::Weak => Self::weak(self.id),
}
}
}
Expand Down Expand Up @@ -320,22 +320,22 @@ impl HandleUntyped {
}
}

pub fn weak(id: HandleId) -> Self {
pub const fn weak(id: HandleId) -> Self {
Self {
id,
handle_type: HandleType::Weak,
}
}

pub fn clone_weak(&self) -> HandleUntyped {
HandleUntyped::weak(self.id)
pub const fn clone_weak(&self) -> Self {
Self::weak(self.id)
}

pub fn is_weak(&self) -> bool {
pub const fn is_weak(&self) -> bool {
matches!(self.handle_type, HandleType::Weak)
}

pub fn is_strong(&self) -> bool {
pub const fn is_strong(&self) -> bool {
matches!(self.handle_type, HandleType::Strong(_))
}

Expand Down Expand Up @@ -398,8 +398,8 @@ impl Eq for HandleUntyped {}
impl Clone for HandleUntyped {
fn clone(&self) -> Self {
match self.handle_type {
HandleType::Strong(ref sender) => HandleUntyped::strong(self.id, sender.clone()),
HandleType::Weak => HandleUntyped::weak(self.id),
HandleType::Strong(ref sender) => Self::strong(self.id, sender.clone()),
HandleType::Weak => Self::weak(self.id),
}
}
}
Expand All @@ -418,6 +418,6 @@ pub(crate) struct RefChangeChannel {
impl Default for RefChangeChannel {
fn default() -> Self {
let (sender, receiver) = crossbeam_channel::unbounded();
RefChangeChannel { sender, receiver }
Self { sender, receiver }
}
}
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/file_asset_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct FileAssetIo {

impl FileAssetIo {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
FileAssetIo {
Self {
#[cfg(feature = "filesystem_watcher")]
filesystem_watcher: Default::default(),
root_path: Self::get_root_path().join(path.as_ref()),
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(crate) struct BoxedLoadedAsset {

impl<T: Asset> From<LoadedAsset<T>> for BoxedLoadedAsset {
fn from(asset: LoadedAsset<T>) -> Self {
BoxedLoadedAsset {
Self {
value: asset
.value
.map(|value| Box::new(value) as Box<dyn AssetDynamic>),
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<'a> LoadContext<'a> {
}
}

pub fn path(&self) -> &Path {
pub const fn path(&self) -> &Path {
ManevilleF marked this conversation as resolved.
Show resolved Hide resolved
self.path
}

Expand Down Expand Up @@ -142,7 +142,7 @@ impl<'a> LoadContext<'a> {
asset_metas
}

pub fn task_pool(&self) -> &TaskPool {
pub const fn task_pool(&self) -> &TaskPool {
ManevilleF marked this conversation as resolved.
Show resolved Hide resolved
self.task_pool
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<T: AssetDynamic> AssetLifecycle for AssetLifecycleChannel<T> {
impl<T> Default for AssetLifecycleChannel<T> {
fn default() -> Self {
let (sender, receiver) = crossbeam_channel::unbounded();
AssetLifecycleChannel { sender, receiver }
Self { sender, receiver }
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a> From<&'a Path> for SourcePathId {
fn from(value: &'a Path) -> Self {
let mut hasher = get_hasher();
value.hash(&mut hasher);
SourcePathId(hasher.finish())
Self(hasher.finish())
}
}

Expand All @@ -99,16 +99,16 @@ impl<'a> From<Option<&'a str>> for LabelId {
fn from(value: Option<&'a str>) -> Self {
let mut hasher = get_hasher();
value.hash(&mut hasher);
LabelId(hasher.finish())
Self(hasher.finish())
}
}

impl AssetPathId {
pub fn source_path_id(&self) -> SourcePathId {
pub const fn source_path_id(&self) -> SourcePathId {
self.0
}

pub fn label_id(&self) -> LabelId {
pub const fn label_id(&self) -> LabelId {
self.1
}
}
Expand All @@ -124,7 +124,7 @@ where
{
fn from(value: T) -> Self {
let asset_path: AssetPath = value.into();
AssetPathId(
Self(
SourcePathId::from(asset_path.path()),
LabelId::from(asset_path.label()),
)
Expand All @@ -133,7 +133,7 @@ where

impl<'a, 'b> From<&'a AssetPath<'b>> for AssetPathId {
fn from(asset_path: &'a AssetPath<'b>) -> Self {
AssetPathId(
Self(
SourcePathId::from(asset_path.path()),
LabelId::from(asset_path.label()),
)
Expand Down
Loading