Skip to content

Commit

Permalink
Remove unnecessary path prefixes (#10749)
Browse files Browse the repository at this point in the history
# Objective

- Shorten paths by removing unnecessary prefixes

## Solution

- Remove the prefixes from many paths which do not need them. Finding
the paths was done automatically using built-in refactoring tools in
Jetbrains RustRover.
  • Loading branch information
tygyh authored Nov 28, 2023
1 parent b19ea0d commit fd30857
Show file tree
Hide file tree
Showing 123 changed files with 335 additions and 414 deletions.
16 changes: 8 additions & 8 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ impl App {
self
}

/// When doing [ambiguity checking](bevy_ecs::schedule::ScheduleBuildSettings) this
/// When doing [ambiguity checking](ScheduleBuildSettings) this
/// ignores systems that are ambiguous on [`Component`] T.
///
/// This settings only applies to the main world. To apply this to other worlds call the
Expand Down Expand Up @@ -927,7 +927,7 @@ impl App {
self
}

/// When doing [ambiguity checking](bevy_ecs::schedule::ScheduleBuildSettings) this
/// When doing [ambiguity checking](ScheduleBuildSettings) this
/// ignores systems that are ambiguous on [`Resource`] T.
///
/// This settings only applies to the main world. To apply this to other worlds call the
Expand Down Expand Up @@ -1004,19 +1004,19 @@ mod tests {

struct PluginA;
impl Plugin for PluginA {
fn build(&self, _app: &mut crate::App) {}
fn build(&self, _app: &mut App) {}
}
struct PluginB;
impl Plugin for PluginB {
fn build(&self, _app: &mut crate::App) {}
fn build(&self, _app: &mut App) {}
}
struct PluginC<T>(T);
impl<T: Send + Sync + 'static> Plugin for PluginC<T> {
fn build(&self, _app: &mut crate::App) {}
fn build(&self, _app: &mut App) {}
}
struct PluginD;
impl Plugin for PluginD {
fn build(&self, _app: &mut crate::App) {}
fn build(&self, _app: &mut App) {}
fn is_unique(&self) -> bool {
false
}
Expand Down Expand Up @@ -1049,10 +1049,10 @@ mod tests {
struct PluginRun;
struct InnerPlugin;
impl Plugin for InnerPlugin {
fn build(&self, _: &mut crate::App) {}
fn build(&self, _: &mut App) {}
}
impl Plugin for PluginRun {
fn build(&self, app: &mut crate::App) {
fn build(&self, app: &mut App) {
app.add_plugins(InnerPlugin).run();
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use proc_macro::{Span, TokenStream};
use quote::{format_ident, quote};
use syn::{parse_macro_input, Data, DeriveInput, Path};

pub(crate) fn bevy_asset_path() -> syn::Path {
pub(crate) fn bevy_asset_path() -> Path {
BevyManifest::default().get_path("bevy_asset")
}

Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_asset/src/io/embedded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub const EMBEDDED: &str = "embedded";
pub struct EmbeddedAssetRegistry {
dir: Dir,
#[cfg(feature = "embedded_watcher")]
root_paths: std::sync::Arc<
parking_lot::RwLock<bevy_utils::HashMap<std::path::PathBuf, std::path::PathBuf>>,
>,
root_paths: std::sync::Arc<parking_lot::RwLock<bevy_utils::HashMap<PathBuf, PathBuf>>>,
}

impl EmbeddedAssetRegistry {
Expand Down
22 changes: 8 additions & 14 deletions crates/bevy_asset/src/io/file/file_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl AssetReader for FileAssetReader {
fn is_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<bool, AssetReaderError>> {
) -> BoxedFuture<'a, Result<bool, AssetReaderError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
let metadata = full_path
Expand Down Expand Up @@ -138,21 +138,15 @@ impl AssetWriter for FileAssetWriter {
})
}

fn remove<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<(), AssetWriterError>> {
fn remove<'a>(&'a self, path: &'a Path) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_file(full_path).await?;
Ok(())
})
}

fn remove_meta<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<(), AssetWriterError>> {
fn remove_meta<'a>(&'a self, path: &'a Path) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let meta_path = get_meta_path(path);
let full_path = self.root_path.join(meta_path);
Expand All @@ -164,7 +158,7 @@ impl AssetWriter for FileAssetWriter {
fn remove_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<(), AssetWriterError>> {
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir_all(full_path).await?;
Expand All @@ -175,7 +169,7 @@ impl AssetWriter for FileAssetWriter {
fn remove_empty_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<(), AssetWriterError>> {
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir(full_path).await?;
Expand All @@ -186,7 +180,7 @@ impl AssetWriter for FileAssetWriter {
fn remove_assets_in_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<(), AssetWriterError>> {
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir_all(&full_path).await?;
Expand All @@ -199,7 +193,7 @@ impl AssetWriter for FileAssetWriter {
&'a self,
old_path: &'a Path,
new_path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<(), AssetWriterError>> {
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_old_path = self.root_path.join(old_path);
let full_new_path = self.root_path.join(new_path);
Expand All @@ -215,7 +209,7 @@ impl AssetWriter for FileAssetWriter {
&'a self,
old_path: &'a Path,
new_path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<(), AssetWriterError>> {
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let old_meta_path = get_meta_path(old_path);
let new_meta_path = get_meta_path(new_path);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/file/file_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub(crate) fn new_asset_event_debouncer(
}

pub(crate) struct FileEventHandler {
sender: crossbeam_channel::Sender<AssetSourceEvent>,
sender: Sender<AssetSourceEvent>,
root: PathBuf,
last_event: Option<AssetSourceEvent>,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/gated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<R: AssetReader> AssetReader for GatedReader<R> {
fn is_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<bool, AssetReaderError>> {
) -> BoxedFuture<'a, Result<bool, AssetReaderError>> {
self.reader.is_directory(path)
}
}
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/io/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ struct DataReader {

impl AsyncRead for DataReader {
fn poll_read(
mut self: std::pin::Pin<&mut Self>,
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
buf: &mut [u8],
) -> std::task::Poll<futures_io::Result<usize>> {
) -> Poll<futures_io::Result<usize>> {
if self.bytes_read >= self.data.value().len() {
Poll::Ready(Ok(0))
} else {
Expand Down Expand Up @@ -286,7 +286,7 @@ impl AssetReader for MemoryAssetReader {
fn is_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<bool, AssetReaderError>> {
) -> BoxedFuture<'a, Result<bool, AssetReaderError>> {
Box::pin(async move { Ok(self.root.get_dir(path).is_some()) })
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ impl VecReader {

impl AsyncRead for VecReader {
fn poll_read(
mut self: std::pin::Pin<&mut Self>,
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
buf: &mut [u8],
) -> std::task::Poll<futures_io::Result<usize>> {
) -> Poll<futures_io::Result<usize>> {
if self.bytes_read >= self.bytes.len() {
Poll::Ready(Ok(0))
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/io/processor_gated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl AssetReader for ProcessorGatedReader {
fn is_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, std::result::Result<bool, AssetReaderError>> {
) -> BoxedFuture<'a, Result<bool, AssetReaderError>> {
Box::pin(async move {
trace!(
"Waiting for processing to finish before reading directory {:?}",
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'a> TransactionLockedReader<'a> {

impl<'a> AsyncRead for TransactionLockedReader<'a> {
fn poll_read(
mut self: std::pin::Pin<&mut Self>,
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
buf: &mut [u8],
) -> std::task::Poll<futures_io::Result<usize>> {
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ compile_error!(
/// Supports flexible "modes", such as [`AssetMode::Processed`] and
/// [`AssetMode::Unprocessed`] that enable using the asset workflow that best suits your project.
///
/// [`AssetSource`]: crate::io::AssetSource
/// [`AssetSource`]: io::AssetSource
pub struct AssetPlugin {
/// The default file path to use (relative to the project root) for unprocessed assets.
pub file_path: String,
Expand All @@ -88,8 +88,8 @@ pub struct AssetPlugin {
pub enum AssetMode {
/// Loads assets from their [`AssetSource`]'s default [`AssetReader`] without any "preprocessing".
///
/// [`AssetReader`]: crate::io::AssetReader
/// [`AssetSource`]: crate::io::AssetSource
/// [`AssetReader`]: io::AssetReader
/// [`AssetSource`]: io::AssetSource
Unprocessed,
/// Assets will be "pre-processed". This enables assets to be imported / converted / optimized ahead of time.
///
Expand All @@ -102,9 +102,9 @@ pub enum AssetMode {
/// be used in combination with the `file_watcher` cargo feature, which enables hot-reloading of assets that have changed. When both features are enabled,
/// changes to "original/source assets" will be detected, the asset will be re-processed, and then the final processed asset will be hot-reloaded in the app.
///
/// [`AssetMeta`]: crate::meta::AssetMeta
/// [`AssetSource`]: crate::io::AssetSource
/// [`AssetReader`]: crate::io::AssetReader
/// [`AssetMeta`]: meta::AssetMeta
/// [`AssetSource`]: io::AssetSource
/// [`AssetReader`]: io::AssetReader
Processed,
}

Expand Down Expand Up @@ -215,9 +215,9 @@ impl Plugin for AssetPlugin {
.init_asset::<()>()
.configure_sets(
UpdateAssets,
TrackAssets.after(server::handle_internal_asset_events),
TrackAssets.after(handle_internal_asset_events),
)
.add_systems(UpdateAssets, server::handle_internal_asset_events);
.add_systems(UpdateAssets, handle_internal_asset_events);

let mut order = app.world.resource_mut::<MainScheduleOrder>();
order.insert_after(First, UpdateAssets);
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,10 @@ impl TypePath for AssetPath<'static> {
Some("AssetPath<'static>")
}
fn crate_name() -> Option<&'static str> {
Option::None
None
}
fn module_path() -> Option<&'static str> {
Option::None
None
}
}
impl Typed for AssetPath<'static> {
Expand All @@ -602,15 +602,15 @@ impl Reflect for AssetPath<'static> {
Some(<Self as Typed>::type_info())
}
#[inline]
fn into_any(self: Box<Self>) -> Box<dyn ::core::any::Any> {
fn into_any(self: Box<Self>) -> Box<dyn core::any::Any> {
self
}
#[inline]
fn as_any(&self) -> &dyn ::core::any::Any {
fn as_any(&self) -> &dyn core::any::Any {
self
}
#[inline]
fn as_any_mut(&mut self) -> &mut dyn ::core::any::Any {
fn as_any_mut(&mut self) -> &mut dyn core::any::Any {
self
}
#[inline]
Expand Down Expand Up @@ -663,19 +663,19 @@ impl Reflect for AssetPath<'static> {
}
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
let value = <dyn Reflect>::as_any(value);
if let Some(value) = <dyn ::core::any::Any>::downcast_ref::<Self>(value) {
Some(::core::cmp::PartialEq::eq(self, value))
if let Some(value) = <dyn core::any::Any>::downcast_ref::<Self>(value) {
Some(PartialEq::eq(self, value))
} else {
Some(false)
}
}
fn debug(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
fn debug(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
::core::fmt::Debug::fmt(self, f)
}
}
impl FromReflect for AssetPath<'static> {
fn from_reflect(reflect: &dyn Reflect) -> Option<Self> {
Some(Clone::clone(<dyn ::core::any::Any>::downcast_ref::<
Some(Clone::clone(<dyn core::any::Any>::downcast_ref::<
AssetPath<'static>,
>(<dyn Reflect>::as_any(reflect))?))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl AssetProcessor {
scope: &'scope bevy_tasks::Scope<'scope, '_, ()>,
source: &'scope AssetSource,
path: PathBuf,
) -> bevy_utils::BoxedFuture<'scope, Result<(), AssetReaderError>> {
) -> BoxedFuture<'scope, Result<(), AssetReaderError>> {
Box::pin(async move {
if source.reader().is_directory(&path).await? {
let mut path_stream = source.reader().read_directory(&path).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_audio/src/audio_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::AudioSink;
///
/// ## Note
///
/// Initializing this resource will leak [`rodio::OutputStream`]
/// Initializing this resource will leak [`OutputStream`]
/// using [`std::mem::forget`].
/// This is done to avoid storing this in the struct (and making this `!Send`)
/// while preventing it from dropping (to avoid halting of audio).
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
/// The hash is eagerly re-computed upon each update to the name.
///
/// [`Name`] should not be treated as a globally unique identifier for entities,
/// as multiple entities can have the same name. [`bevy_ecs::entity::Entity`] should be
/// as multiple entities can have the same name. [`Entity`] should be
/// used instead as the default unique identifier.
#[derive(Reflect, Component, Clone)]
#[reflect(Component, Default, Debug)]
Expand Down
22 changes: 10 additions & 12 deletions crates/bevy_core_pipeline/src/tonemapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,16 @@ pub fn get_lut_bind_group_layout_entries() -> [BindGroupLayoutEntryBuilder; 2] {
// allow(dead_code) so it doesn't complain when the tonemapping_luts feature is disabled
#[allow(dead_code)]
fn setup_tonemapping_lut_image(bytes: &[u8], image_type: ImageType) -> Image {
let image_sampler = bevy_render::texture::ImageSampler::Descriptor(
bevy_render::texture::ImageSamplerDescriptor {
label: Some("Tonemapping LUT sampler".to_string()),
address_mode_u: bevy_render::texture::ImageAddressMode::ClampToEdge,
address_mode_v: bevy_render::texture::ImageAddressMode::ClampToEdge,
address_mode_w: bevy_render::texture::ImageAddressMode::ClampToEdge,
mag_filter: bevy_render::texture::ImageFilterMode::Linear,
min_filter: bevy_render::texture::ImageFilterMode::Linear,
mipmap_filter: bevy_render::texture::ImageFilterMode::Linear,
..default()
},
);
let image_sampler = ImageSampler::Descriptor(bevy_render::texture::ImageSamplerDescriptor {
label: Some("Tonemapping LUT sampler".to_string()),
address_mode_u: bevy_render::texture::ImageAddressMode::ClampToEdge,
address_mode_v: bevy_render::texture::ImageAddressMode::ClampToEdge,
address_mode_w: bevy_render::texture::ImageAddressMode::ClampToEdge,
mag_filter: bevy_render::texture::ImageFilterMode::Linear,
min_filter: bevy_render::texture::ImageFilterMode::Linear,
mipmap_filter: bevy_render::texture::ImageFilterMode::Linear,
..default()
});
Image::from_buffer(
bytes,
image_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_time::{Real, Time};
pub struct FrameTimeDiagnosticsPlugin;

impl Plugin for FrameTimeDiagnosticsPlugin {
fn build(&self, app: &mut bevy_app::App) {
fn build(&self, app: &mut App) {
app.register_diagnostic(
Diagnostic::new(Self::FRAME_TIME, "frame_time", 20).with_suffix("ms"),
)
Expand Down
Loading

0 comments on commit fd30857

Please sign in to comment.