Re-export smallvec crate from bevy_utils (#11006)

Matches versioning & features from other Cargo.toml files in the
project.

# Objective
Resolves #10932 

## Solution
Added smallvec to the bevy_utils cargo.toml and added a line to
re-export the crate. Target version and features set to match what's
used in the other bevy crates.
This commit is contained in:
David Cosby 2023-12-24 08:35:09 -07:00 committed by GitHub
parent e61da11fcc
commit 42b737878f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 24 additions and 22 deletions

View File

@ -25,8 +25,5 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.12.0", features = [
], optional = true } ], optional = true }
bevy_utils = { path = "../bevy_utils", version = "0.12.0" } bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
# other
smallvec = { version = "1.6", features = ["serde", "union", "const_generics"] }
[lints] [lints]
workspace = true workspace = true

View File

@ -6,7 +6,7 @@ use bevy_ecs::{
system::{Command, Commands, EntityCommands}, system::{Command, Commands, EntityCommands},
world::{EntityWorldMut, World}, world::{EntityWorldMut, World},
}; };
use smallvec::SmallVec; use bevy_utils::smallvec::{smallvec, SmallVec};
// Do not use `world.send_event_batch` as it prints error message when the Events are not available in the world, // Do not use `world.send_event_batch` as it prints error message when the Events are not available in the world,
// even though it's a valid use case to execute commands on a world without events. Loading a GLTF file for example // even though it's a valid use case to execute commands on a world without events. Loading a GLTF file for example
@ -24,7 +24,7 @@ fn push_child_unchecked(world: &mut World, parent: Entity, child: Entity) {
if let Some(mut children) = parent.get_mut::<Children>() { if let Some(mut children) = parent.get_mut::<Children>() {
children.0.push(child); children.0.push(child);
} else { } else {
parent.insert(Children(smallvec::smallvec![child])); parent.insert(Children(smallvec![child]));
} }
} }
@ -696,7 +696,7 @@ mod tests {
components::{Children, Parent}, components::{Children, Parent},
HierarchyEvent::{self, ChildAdded, ChildMoved, ChildRemoved}, HierarchyEvent::{self, ChildAdded, ChildMoved, ChildRemoved},
}; };
use smallvec::{smallvec, SmallVec}; use bevy_utils::smallvec::{smallvec, SmallVec};
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component,

View File

@ -6,8 +6,8 @@ use bevy_ecs::{
prelude::FromWorld, prelude::FromWorld,
world::World, world::World,
}; };
use bevy_utils::smallvec::SmallVec;
use core::slice; use core::slice;
use smallvec::SmallVec;
use std::ops::Deref; use std::ops::Deref;
/// Contains references to the child entities of this entity. /// Contains references to the child entities of this entity.

View File

@ -40,11 +40,12 @@ use bevy_app::prelude::*;
pub struct HierarchyPlugin; pub struct HierarchyPlugin;
#[cfg(feature = "bevy_app")] #[cfg(feature = "bevy_app")]
use bevy_utils::smallvec::SmallVec;
impl Plugin for HierarchyPlugin { impl Plugin for HierarchyPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.register_type::<Children>() app.register_type::<Children>()
.register_type::<Parent>() .register_type::<Parent>()
.register_type::<smallvec::SmallVec<[bevy_ecs::entity::Entity; 8]>>() .register_type::<SmallVec<[bevy_ecs::entity::Entity; 8]>>()
.add_event::<HierarchyEvent>(); .add_event::<HierarchyEvent>();
} }
} }

View File

@ -35,7 +35,6 @@ fixedbitset = "0.4"
bytemuck = { version = "1", features = ["derive"] } bytemuck = { version = "1", features = ["derive"] }
radsort = "0.1" radsort = "0.1"
naga_oil = "0.11" naga_oil = "0.11"
smallvec = "1.6"
thread_local = "1.0" thread_local = "1.0"
[lints] [lints]

View File

@ -13,6 +13,7 @@ readme = "README.md"
default = [] default = []
# When enabled, provides Bevy-related reflection implementations # When enabled, provides Bevy-related reflection implementations
bevy = ["glam", "smallvec", "bevy_math", "smol_str"] bevy = ["glam", "smallvec", "bevy_math", "smol_str"]
smallvec = []
# When enabled, allows documentation comments to be accessed via reflection # When enabled, allows documentation comments to be accessed via reflection
documentation = ["bevy_reflect_derive/documentation"] documentation = ["bevy_reflect_derive/documentation"]
@ -30,11 +31,7 @@ erased-serde = "0.3"
downcast-rs = "1.2" downcast-rs = "1.2"
thiserror = "1.0" thiserror = "1.0"
serde = "1" serde = "1"
smallvec = { version = "1.6", features = [
"serde",
"union",
"const_generics",
], optional = true }
glam = { version = "0.24.1", features = ["serde"], optional = true } glam = { version = "0.24.1", features = ["serde"], optional = true }
smol_str = { version = "0.2.0", optional = true } smol_str = { version = "0.2.0", optional = true }

View File

@ -1,5 +1,7 @@
use bevy_reflect_derive::impl_type_path; use bevy_reflect_derive::impl_type_path;
use bevy_utils::smallvec;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::any::Any; use std::any::Any;
use crate::utility::GenericTypeInfoCell; use crate::utility::GenericTypeInfoCell;
@ -148,7 +150,7 @@ where
} }
} }
impl_type_path!(::smallvec::SmallVec<T: smallvec::Array>); impl_type_path!(::bevy_utils::smallvec::SmallVec<T: smallvec::Array>);
impl<T: smallvec::Array + TypePath + Send + Sync> FromReflect for SmallVec<T> impl<T: smallvec::Array + TypePath + Send + Sync> FromReflect for SmallVec<T>
where where

View File

@ -1383,6 +1383,7 @@ mod tests {
// List (SmallVec) // List (SmallVec)
#[cfg(feature = "smallvec")] #[cfg(feature = "smallvec")]
{ {
use bevy_utils::smallvec;
type MySmallVec = smallvec::SmallVec<[String; 2]>; type MySmallVec = smallvec::SmallVec<[String; 2]>;
let info = MySmallVec::type_info(); let info = MySmallVec::type_info();

View File

@ -2,8 +2,10 @@ use crate::TypeUuid;
use crate::{self as bevy_reflect, __macro_exports::generate_composite_uuid}; use crate::{self as bevy_reflect, __macro_exports::generate_composite_uuid};
use bevy_reflect_derive::impl_type_uuid; use bevy_reflect_derive::impl_type_uuid;
use bevy_utils::{all_tuples, Duration, HashMap, HashSet, Instant, Uuid}; use bevy_utils::{all_tuples, Duration, HashMap, HashSet, Instant, Uuid};
#[cfg(feature = "smallvec")] #[cfg(feature = "smallvec")]
use smallvec::SmallVec; use bevy_utils::{smallvec, smallvec::SmallVec};
#[cfg(any(unix, windows))] #[cfg(any(unix, windows))]
use std::ffi::OsString; use std::ffi::OsString;
use std::{ use std::{

View File

@ -71,7 +71,6 @@ naga_oil = "0.11"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
bitflags = "2.3" bitflags = "2.3"
bytemuck = { version = "1.5", features = ["derive"] } bytemuck = { version = "1.5", features = ["derive"] }
smallvec = { version = "1.6", features = ["union", "const_generics"] }
downcast-rs = "1.2.0" downcast-rs = "1.2.0"
thread_local = "1.1" thread_local = "1.1"
thiserror = "1.0" thiserror = "1.0"

View File

@ -1,8 +1,11 @@
use bevy_ecs::{prelude::Entity, world::World}; use bevy_ecs::{prelude::Entity, world::World};
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
use bevy_utils::tracing::info_span; use bevy_utils::tracing::info_span;
use bevy_utils::HashMap; use bevy_utils::{
use smallvec::{smallvec, SmallVec}; smallvec::{smallvec, SmallVec},
HashMap,
};
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
use std::ops::Deref; use std::ops::Deref;
use std::{borrow::Cow, collections::VecDeque}; use std::{borrow::Cow, collections::VecDeque};

View File

@ -33,7 +33,6 @@ bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
# other # other
taffy = { version = "0.3.10" } taffy = { version = "0.3.10" }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
smallvec = { version = "1.6", features = ["union", "const_generics"] }
bytemuck = { version = "1.5", features = ["derive"] } bytemuck = { version = "1.5", features = ["derive"] }
thiserror = "1.0.0" thiserror = "1.0.0"

View File

@ -13,9 +13,9 @@ use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_render::{camera::NormalizedRenderTarget, prelude::Camera, view::ViewVisibility}; use bevy_render::{camera::NormalizedRenderTarget, prelude::Camera, view::ViewVisibility};
use bevy_transform::components::GlobalTransform; use bevy_transform::components::GlobalTransform;
use bevy_utils::smallvec::SmallVec;
use bevy_window::{PrimaryWindow, Window}; use bevy_window::{PrimaryWindow, Window};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
/// Describes what type of input interaction has occurred for a UI node. /// Describes what type of input interaction has occurred for a UI node.
/// ///

View File

@ -5,8 +5,8 @@ use bevy_math::{Rect, Vec2};
use bevy_reflect::prelude::*; use bevy_reflect::prelude::*;
use bevy_render::{color::Color, texture::Image}; use bevy_render::{color::Color, texture::Image};
use bevy_transform::prelude::GlobalTransform; use bevy_transform::prelude::GlobalTransform;
use bevy_utils::smallvec::SmallVec;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use std::num::{NonZeroI16, NonZeroU16}; use std::num::{NonZeroI16, NonZeroU16};
use thiserror::Error; use thiserror::Error;

View File

@ -21,6 +21,7 @@ bevy_utils_proc_macros = { version = "0.12.0", path = "macros" }
petgraph = "0.6" petgraph = "0.6"
thiserror = "1.0" thiserror = "1.0"
nonmax = "0.5" nonmax = "0.5"
smallvec = { version = "1.11", features = ["serde", "union", "const_generics"] }
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2.0", features = ["js"] } getrandom = { version = "0.2.0", features = ["js"] }

View File

@ -32,6 +32,7 @@ pub use default::default;
pub use float_ord::*; pub use float_ord::*;
pub use hashbrown; pub use hashbrown;
pub use petgraph; pub use petgraph;
pub use smallvec;
pub use thiserror; pub use thiserror;
pub use tracing; pub use tracing;
pub use web_time::{Duration, Instant, SystemTime, SystemTimeError, TryFromFloatSecsError}; pub use web_time::{Duration, Instant, SystemTime, SystemTimeError, TryFromFloatSecsError};