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

Switch bevy_asset to core::prelude #17442

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bevy_asset/src/asset_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ unsafe impl<A: AsAssetId> QueryFilter for AssetChanged<A> {
#[cfg(test)]
mod tests {
use crate::{self as bevy_asset, AssetEvents, AssetPlugin, Handle};
use alloc::{vec, vec::Vec};
use core::num::NonZero;
use std::println;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boo!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, I wonder if Bevy should actually prohibit eprintln and println since we always have access to log and/or tracing...


use crate::{AssetApp, Assets};
use bevy_app::{App, AppExit, Last, Startup, TaskPoolPlugin, Update};
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
self as bevy_asset, Asset, AssetEvent, AssetHandleProvider, AssetId, AssetServer, Handle,
UntypedHandle,
};
use alloc::sync::Arc;
use alloc::{sync::Arc, vec::Vec};
use bevy_ecs::{
prelude::EventWriter,
system::{Res, ResMut, Resource, SystemChangeTick},
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_asset/src/folder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

use crate as bevy_asset;
use crate::{Asset, UntypedHandle};
use bevy_reflect::TypePath;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ pub enum UntypedAssetConversionError {

#[cfg(test)]
mod tests {
use alloc::boxed::Box;
use bevy_reflect::PartialReflect;
use bevy_utils::FixedHasher;
use core::hash::BuildHasher;
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/io/android.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::io::{get_meta_path, AssetReader, AssetReaderError, PathStream, Reader, VecReader};
use alloc::ffi::CString;
use futures_lite::stream;
use std::{ffi::CString, path::Path};
use std::path::Path;
use tracing::error;

/// [`AssetReader`] implementation for Android devices, built on top of Android's [`AssetManager`].
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/embedded/embedded_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::io::{
memory::Dir,
AssetSourceEvent, AssetWatcher,
};
use alloc::sync::Arc;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use bevy_utils::HashMap;
use core::time::Duration;
use notify_debouncer_full::{notify::RecommendedWatcher, Debouncer, RecommendedCache};
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_asset/src/io/embedded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ use crate::io::{
memory::{Dir, MemoryAssetReader, Value},
AssetSource, AssetSourceBuilders,
};
use alloc::boxed::Box;
use bevy_ecs::system::Resource;
use std::path::{Path, PathBuf};

#[cfg(feature = "embedded_watcher")]
use alloc::borrow::ToOwned;

pub const EMBEDDED: &str = "embedded";

/// A [`Resource`] that manages "rust source files" in a virtual in memory [`Dir`], which is intended
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/src/io/file/file_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use async_fs::{read_dir, File};
use futures_io::AsyncSeek;
use futures_lite::StreamExt;

use alloc::{borrow::ToOwned, boxed::Box};
use core::{pin::Pin, task, task::Poll};
use std::path::Path;

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/src/io/file/file_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
io::{AssetSourceEvent, AssetWatcher},
path::normalize_path,
};
use alloc::borrow::ToOwned;
use core::time::Duration;
use crossbeam_channel::Sender;
use notify_debouncer_full::{
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/src/io/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod sync_file_asset;
pub use file_watcher::*;
use tracing::{debug, error};

use alloc::borrow::ToOwned;
use std::{
env,
path::{Path, PathBuf},
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/src/io/file/sync_file_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::io::{
PathStream, Reader, Writer,
};

use alloc::{borrow::ToOwned, boxed::Box, vec::Vec};
use core::{pin::Pin, task::Poll};
use std::{
fs::{read_dir, File},
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
@@ -1,5 +1,5 @@
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::sync::Arc;
use alloc::{boxed::Box, sync::Arc};
use bevy_utils::HashMap;
use crossbeam_channel::{Receiver, Sender};
use parking_lot::RwLock;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/memory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::sync::Arc;
use alloc::{borrow::ToOwned, boxed::Box, sync::Arc, vec::Vec};
use bevy_utils::HashMap;
use core::{pin::Pin, task::Poll};
use futures_io::AsyncRead;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod source;
pub use futures_lite::AsyncWriteExt;
pub use source::*;

use alloc::sync::Arc;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
use core::future::Future;
use core::{
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/processor_gated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
processor::{AssetProcessorData, ProcessStatus},
AssetPath,
};
use alloc::sync::Arc;
use alloc::{borrow::ToOwned, boxed::Box, sync::Arc, vec::Vec};
use async_lock::RwLockReadGuardArc;
use core::{pin::Pin, task::Poll};
use futures_io::AsyncRead;
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_asset/src/io/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use crate::{
io::{processor_gated::ProcessorGatedReader, AssetSourceEvent, AssetWatcher},
processor::AssetProcessorData,
};
use alloc::sync::Arc;
use alloc::{
boxed::Box,
string::{String, ToString},
sync::Arc,
};
use atomicow::CowArc;
use bevy_ecs::system::Resource;
use bevy_utils::HashMap;
Expand Down
18 changes: 15 additions & 3 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@
html_logo_url = "https://bevyengine.org/assets/icon.png",
html_favicon_url = "https://bevyengine.org/assets/icon.png"
)]
#![no_std]

extern crate alloc;
extern crate core;
extern crate std;

pub mod io;
pub mod meta;
Expand Down Expand Up @@ -206,7 +207,11 @@ use crate::{
io::{embedded::EmbeddedAssetRegistry, AssetSourceBuilder, AssetSourceBuilders, AssetSourceId},
processor::{AssetProcessor, Process},
};
use alloc::sync::Arc;
use alloc::{
string::{String, ToString},
sync::Arc,
vec::Vec,
};
use bevy_app::{App, Last, Plugin, PreUpdate};
use bevy_ecs::prelude::Component;
use bevy_ecs::{
Expand Down Expand Up @@ -633,7 +638,14 @@ mod tests {
Asset, AssetApp, AssetEvent, AssetId, AssetLoadError, AssetLoadFailedEvent, AssetPath,
AssetPlugin, AssetServer, Assets,
};
use alloc::sync::Arc;
use alloc::{
boxed::Box,
format,
string::{String, ToString},
sync::Arc,
vec,
vec::Vec,
};
use bevy_app::{App, TaskPoolPlugin, Update};
use bevy_ecs::{
event::EventCursor,
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use crate::{
Asset, AssetLoadError, AssetServer, AssetServerMode, Assets, Handle, UntypedAssetId,
UntypedHandle,
};
use alloc::{
boxed::Box,
string::{String, ToString},
vec::Vec,
};
use atomicow::CowArc;
use bevy_ecs::world::World;
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/loader_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
Asset, AssetLoadError, AssetPath, ErasedAssetLoader, ErasedLoadedAsset, Handle, LoadContext,
LoadDirectError, LoadedAsset, LoadedUntypedAsset, UntypedHandle,
};
use alloc::sync::Arc;
use alloc::{borrow::ToOwned, boxed::Box, sync::Arc};
use core::any::TypeId;

// Utility type for handling the sources of reader references
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_asset/src/meta.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use alloc::{
boxed::Box,
string::{String, ToString},
vec::Vec,
};

use crate::{
self as bevy_asset, loader::AssetLoader, processor::Process, Asset, AssetPath,
DeserializeMetaError, VisitAssetDependencies,
Expand Down
9 changes: 7 additions & 2 deletions crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::io::AssetSourceId;
use alloc::{
borrow::ToOwned,
string::{String, ToString},
};
use atomicow::CowArc;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use core::{
Expand Down Expand Up @@ -316,7 +320,7 @@ impl<'a> AssetPath<'a> {
/// If internally a value is a static reference, the static reference will be used unchanged.
/// If internally a value is an "owned [`Arc`]", it will remain unchanged.
///
/// [`Arc`]: std::sync::Arc
/// [`Arc`]: alloc::sync::Arc
pub fn into_owned(self) -> AssetPath<'static> {
AssetPath {
source: self.source.into_owned(),
Expand All @@ -329,7 +333,7 @@ impl<'a> AssetPath<'a> {
/// If internally a value is a static reference, the static reference will be used unchanged.
/// If internally a value is an "owned [`Arc`]", the [`Arc`] will be cloned.
///
/// [`Arc`]: std::sync::Arc
/// [`Arc`]: alloc::sync::Arc
#[inline]
pub fn clone_owned(&self) -> AssetPath<'static> {
self.clone().into_owned()
Expand Down Expand Up @@ -629,6 +633,7 @@ pub(crate) fn normalize_path(path: &Path) -> PathBuf {
#[cfg(test)]
mod tests {
use crate::AssetPath;
use alloc::string::ToString;
use std::path::Path;

#[test]
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_asset/src/processor/log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use crate::AssetPath;
use alloc::{
format,
string::{String, ToString},
vec::Vec,
};
use async_fs::File;
use bevy_utils::HashSet;
use futures_lite::{AsyncReadExt, AsyncWriteExt};
Expand Down
11 changes: 7 additions & 4 deletions crates/bevy_asset/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ use crate::{
AssetLoadError, AssetMetaCheck, AssetPath, AssetServer, AssetServerMode, DeserializeMetaError,
MissingAssetLoaderForExtensionError,
};
use alloc::{collections::VecDeque, sync::Arc};
use alloc::{borrow::ToOwned, boxed::Box, collections::VecDeque, sync::Arc, vec, vec::Vec};
use bevy_ecs::prelude::*;
#[cfg(feature = "trace")]
use bevy_tasks::ConditionalSendFuture;
use bevy_tasks::IoTaskPool;
use bevy_utils::{HashMap, HashSet};
use futures_io::ErrorKind;
Expand All @@ -68,8 +66,13 @@ use parking_lot::RwLock;
use std::path::{Path, PathBuf};
use thiserror::Error;
use tracing::{debug, error, trace, warn};

#[cfg(feature = "trace")]
use tracing::{info_span, instrument::Instrument};
use {
alloc::string::ToString,
bevy_tasks::ConditionalSendFuture,
tracing::{info_span, instrument::Instrument},
};

/// A "background" asset processor that reads asset values from a source [`AssetSource`] (which corresponds to an [`AssetReader`](crate::io::AssetReader) / [`AssetWriter`](crate::io::AssetWriter) pair),
/// processes them in some way, and writes them to a destination [`AssetSource`].
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_asset/src/processor/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use crate::{
AssetLoadError, AssetLoader, AssetPath, DeserializeMetaError, ErasedLoadedAsset,
MissingAssetLoaderForExtensionError, MissingAssetLoaderForTypeNameError,
};
use alloc::{
borrow::ToOwned,
boxed::Box,
string::{String, ToString},
};
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
use core::marker::PhantomData;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_asset/src/reflect.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::boxed::Box;
use core::any::{Any, TypeId};

use bevy_ecs::world::{unsafe_world_cell::UnsafeWorldCell, World};
Expand Down Expand Up @@ -243,6 +244,7 @@ impl<A: Asset> FromType<Handle<A>> for ReflectHandle {

#[cfg(test)]
mod tests {
use alloc::{string::String, vec::Vec};
use core::any::TypeId;

use crate as bevy_asset;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/src/saver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
io::Writer, meta::Settings, transformer::TransformedAsset, Asset, AssetLoader,
ErasedLoadedAsset, Handle, LabeledAsset, UntypedHandle,
};
use alloc::boxed::Box;
use atomicow::CowArc;
use bevy_tasks::{BoxedFuture, ConditionalSendFuture};
use bevy_utils::HashMap;
Expand Down
7 changes: 6 additions & 1 deletion crates/bevy_asset/src/server/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use crate::{
Handle, InternalAssetEvent, LoadState, RecursiveDependencyLoadState, StrongHandle,
UntypedAssetId, UntypedHandle,
};
use alloc::sync::{Arc, Weak};
use alloc::{
borrow::ToOwned,
boxed::Box,
sync::{Arc, Weak},
vec::Vec,
};
use bevy_ecs::world::World;
use bevy_tasks::Task;
use bevy_utils::{Entry, HashMap, HashSet, TypeIdMap};
Expand Down
12 changes: 8 additions & 4 deletions crates/bevy_asset/src/server/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ use crate::{
loader::{AssetLoader, ErasedAssetLoader},
path::AssetPath,
};
use alloc::sync::Arc;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use async_broadcast::RecvError;
#[cfg(feature = "trace")]
use bevy_tasks::ConditionalSendFuture;
use bevy_tasks::IoTaskPool;
use bevy_utils::{HashMap, TypeIdMap};
use core::any::TypeId;
use thiserror::Error;
use tracing::warn;

#[cfg(feature = "trace")]
use tracing::{info_span, instrument::Instrument};
use {
alloc::string::ToString,
bevy_tasks::ConditionalSendFuture,
tracing::{info_span, instrument::Instrument},
};

#[derive(Default)]
pub(crate) struct AssetLoaders {
Expand Down Expand Up @@ -338,6 +341,7 @@ impl<T: AssetLoader> AssetLoader for InstrumentedAssetLoader<T> {

#[cfg(test)]
mod tests {
use alloc::{format, string::String};
use core::marker::PhantomData;
use std::{
path::Path,
Expand Down
Loading
Loading