Skip to content

Commit 8f32c79

Browse files
Switch bevy_asset to core::prelude (#17442)
Makes use of `std` explicit, simplifying a possible `no_std` port. # Objective - Contributes to #15460 - Simplify future `no_std` work on `bevy_asset` ## Solution - Add `#![no_std]` to switch to `core::prelude` instead of `std::prelude` ## Testing - CI --- ## Notes This is entirely a change around the names of imports and has no impact on functionality. This just reduces the quantity of changes involved in the (likely more controversial) `no_std`-ification of `bevy_asset`.
1 parent 5d0e9cf commit 8f32c79

31 files changed

+109
-34
lines changed

crates/bevy_asset/src/asset_changed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ unsafe impl<A: AsAssetId> QueryFilter for AssetChanged<A> {
288288
#[cfg(test)]
289289
mod tests {
290290
use crate::{self as bevy_asset, AssetEvents, AssetPlugin, Handle};
291+
use alloc::{vec, vec::Vec};
291292
use core::num::NonZero;
293+
use std::println;
292294

293295
use crate::{AssetApp, Assets};
294296
use bevy_app::{App, AppExit, Last, Startup, TaskPoolPlugin, Update};

crates/bevy_asset/src/assets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
self as bevy_asset, Asset, AssetEvent, AssetHandleProvider, AssetId, AssetServer, Handle,
44
UntypedHandle,
55
};
6-
use alloc::sync::Arc;
6+
use alloc::{sync::Arc, vec::Vec};
77
use bevy_ecs::{
88
prelude::EventWriter,
99
system::{Res, ResMut, Resource, SystemChangeTick},

crates/bevy_asset/src/folder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use alloc::vec::Vec;
2+
13
use crate as bevy_asset;
24
use crate::{Asset, UntypedHandle};
35
use bevy_reflect::TypePath;

crates/bevy_asset/src/handle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ pub enum UntypedAssetConversionError {
514514

515515
#[cfg(test)]
516516
mod tests {
517+
use alloc::boxed::Box;
517518
use bevy_reflect::PartialReflect;
518519
use bevy_utils::FixedHasher;
519520
use core::hash::BuildHasher;

crates/bevy_asset/src/io/android.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::io::{get_meta_path, AssetReader, AssetReaderError, PathStream, Reader, VecReader};
2+
use alloc::{borrow::ToOwned, boxed::Box, ffi::CString, vec::Vec};
23
use futures_lite::stream;
3-
use std::{ffi::CString, path::Path};
4-
use tracing::error;
4+
use std::path::Path;
55

66
/// [`AssetReader`] implementation for Android devices, built on top of Android's [`AssetManager`].
77
///
@@ -72,10 +72,7 @@ impl AssetReader for AndroidAssetReader {
7272
Ok(read_dir)
7373
}
7474

75-
async fn is_directory<'a>(
76-
&'a self,
77-
path: &'a Path,
78-
) -> std::result::Result<bool, AssetReaderError> {
75+
async fn is_directory<'a>(&'a self, path: &'a Path) -> Result<bool, AssetReaderError> {
7976
let asset_manager = bevy_window::ANDROID_APP
8077
.get()
8178
.expect("Bevy must be setup with the #[bevy_main] macro on Android")

crates/bevy_asset/src/io/embedded/embedded_watcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::io::{
33
memory::Dir,
44
AssetSourceEvent, AssetWatcher,
55
};
6-
use alloc::sync::Arc;
6+
use alloc::{boxed::Box, sync::Arc, vec::Vec};
77
use bevy_utils::HashMap;
88
use core::time::Duration;
99
use notify_debouncer_full::{notify::RecommendedWatcher, Debouncer, RecommendedCache};

crates/bevy_asset/src/io/embedded/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ use crate::io::{
88
memory::{Dir, MemoryAssetReader, Value},
99
AssetSource, AssetSourceBuilders,
1010
};
11+
use alloc::boxed::Box;
1112
use bevy_ecs::system::Resource;
1213
use std::path::{Path, PathBuf};
1314

15+
#[cfg(feature = "embedded_watcher")]
16+
use alloc::borrow::ToOwned;
17+
1418
pub const EMBEDDED: &str = "embedded";
1519

1620
/// A [`Resource`] that manages "rust source files" in a virtual in memory [`Dir`], which is intended
@@ -29,7 +33,7 @@ impl EmbeddedAssetRegistry {
2933
/// Inserts a new asset. `full_path` is the full path (as [`file`] would return for that file, if it was capable of
3034
/// running in a non-rust file). `asset_path` is the path that will be used to identify the asset in the `embedded`
3135
/// [`AssetSource`]. `value` is the bytes that will be returned for the asset. This can be _either_ a `&'static [u8]`
32-
/// or a [`Vec<u8>`].
36+
/// or a [`Vec<u8>`](alloc::vec::Vec).
3337
#[cfg_attr(
3438
not(feature = "embedded_watcher"),
3539
expect(
@@ -48,7 +52,7 @@ impl EmbeddedAssetRegistry {
4852
/// Inserts new asset metadata. `full_path` is the full path (as [`file`] would return for that file, if it was capable of
4953
/// running in a non-rust file). `asset_path` is the path that will be used to identify the asset in the `embedded`
5054
/// [`AssetSource`]. `value` is the bytes that will be returned for the asset. This can be _either_ a `&'static [u8]`
51-
/// or a [`Vec<u8>`].
55+
/// or a [`Vec<u8>`](alloc::vec::Vec).
5256
#[cfg_attr(
5357
not(feature = "embedded_watcher"),
5458
expect(

crates/bevy_asset/src/io/file/file_asset.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use async_fs::{read_dir, File};
66
use futures_io::AsyncSeek;
77
use futures_lite::StreamExt;
88

9+
use alloc::{borrow::ToOwned, boxed::Box};
910
use core::{pin::Pin, task, task::Poll};
1011
use std::path::Path;
1112

crates/bevy_asset/src/io/file/file_watcher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
io::{AssetSourceEvent, AssetWatcher},
33
path::normalize_path,
44
};
5+
use alloc::borrow::ToOwned;
56
use core::time::Duration;
67
use crossbeam_channel::Sender;
78
use notify_debouncer_full::{

crates/bevy_asset/src/io/file/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod sync_file_asset;
1010
pub use file_watcher::*;
1111
use tracing::{debug, error};
1212

13+
use alloc::borrow::ToOwned;
1314
use std::{
1415
env,
1516
path::{Path, PathBuf},

0 commit comments

Comments
 (0)