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

Use impl Into<A> for Assets::add #10878

Merged
merged 2 commits into from Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/assets.rs
Expand Up @@ -359,9 +359,9 @@ impl<A: Asset> Assets<A> {

/// Adds the given `asset` and allocates a new strong [`Handle`] for it.
#[inline]
pub fn add(&mut self, asset: A) -> Handle<A> {
pub fn add(&mut self, asset: impl Into<A>) -> Handle<A> {
let index = self.dense_storage.allocator.reserve();
self.insert_with_index(index, asset).unwrap();
self.insert_with_index(index, asset.into()).unwrap();
Handle::Strong(
self.handle_provider
.get_handle(index.into(), false, None, None),
Expand Down
8 changes: 4 additions & 4 deletions errors/B0004.md
Expand Up @@ -33,8 +33,8 @@ fn setup_cube(
.with_children(|parent| {
// cube
parent.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
Expand Down Expand Up @@ -80,8 +80,8 @@ fn setup_cube(
.with_children(|parent| {
// cube
parent.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
Expand Down
8 changes: 3 additions & 5 deletions examples/2d/2d_shapes.rs
Expand Up @@ -18,7 +18,7 @@ fn setup(

// Circle
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(50.).into()).into(),
mesh: meshes.add(shape::Circle::new(50.)).into(),
material: materials.add(ColorMaterial::from(Color::PURPLE)),
transform: Transform::from_translation(Vec3::new(-150., 0., 0.)),
..default()
Expand All @@ -37,17 +37,15 @@ fn setup(

// Quad
commands.spawn(MaterialMesh2dBundle {
mesh: meshes
.add(shape::Quad::new(Vec2::new(50., 100.)).into())
.into(),
mesh: meshes.add(shape::Quad::new(Vec2::new(50., 100.))).into(),
material: materials.add(ColorMaterial::from(Color::LIME_GREEN)),
transform: Transform::from_translation(Vec3::new(50., 0., 0.)),
..default()
});

// Hexagon
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::RegularPolygon::new(50., 6).into()).into(),
mesh: meshes.add(shape::RegularPolygon::new(50., 6)).into(),
material: materials.add(ColorMaterial::from(Color::TURQUOISE)),
transform: Transform::from_translation(Vec3::new(150., 0., 0.)),
..default()
Expand Down
6 changes: 2 additions & 4 deletions examples/2d/bloom_2d.rs
Expand Up @@ -48,7 +48,7 @@ fn setup(

// Circle mesh
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(100.).into()).into(),
mesh: meshes.add(shape::Circle::new(100.)).into(),
// 4. Put something bright in a dark environment to see the effect
material: materials.add(ColorMaterial::from(Color::rgb(7.5, 0.0, 7.5))),
transform: Transform::from_translation(Vec3::new(-200., 0., 0.)),
Expand All @@ -57,9 +57,7 @@ fn setup(

// Hexagon mesh
commands.spawn(MaterialMesh2dBundle {
mesh: meshes
.add(shape::RegularPolygon::new(100., 6).into())
.into(),
mesh: meshes.add(shape::RegularPolygon::new(100., 6)).into(),
// 4. Put something bright in a dark environment to see the effect
material: materials.add(ColorMaterial::from(Color::rgb(6.25, 9.4, 9.1))),
transform: Transform::from_translation(Vec3::new(200., 0., 0.)),
Expand Down
2 changes: 1 addition & 1 deletion examples/2d/mesh2d.rs
Expand Up @@ -18,7 +18,7 @@ fn setup(
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(shape::Quad::default())).into(),
mesh: meshes.add(shape::Quad::default()).into(),
transform: Transform::default().with_scale(Vec3::splat(128.)),
material: materials.add(ColorMaterial::from(Color::PURPLE)),
..default()
Expand Down
8 changes: 4 additions & 4 deletions examples/3d/3d_gizmos.rs
Expand Up @@ -23,14 +23,14 @@ fn setup(
});
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(shape::Plane::from_size(5.0)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
Expand Down
8 changes: 4 additions & 4 deletions examples/3d/3d_scene.rs
Expand Up @@ -17,15 +17,15 @@ fn setup(
) {
// circular base
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Circle::new(4.0).into()),
material: materials.add(Color::WHITE.into()),
mesh: meshes.add(shape::Circle::new(4.0)),
material: materials.add(Color::WHITE),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb_u8(124, 144, 255).into()),
mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::rgb_u8(124, 144, 255)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
Expand Down
18 changes: 9 additions & 9 deletions examples/3d/3d_shapes.rs
Expand Up @@ -34,13 +34,13 @@ fn setup(
});

let shapes = [
meshes.add(shape::Cube::default().into()),
meshes.add(shape::Box::default().into()),
meshes.add(shape::Capsule::default().into()),
meshes.add(shape::Torus::default().into()),
meshes.add(shape::Cylinder::default().into()),
meshes.add(shape::Icosphere::default().try_into().unwrap()),
meshes.add(shape::UVSphere::default().into()),
meshes.add(shape::Cube::default()),
meshes.add(shape::Box::default()),
meshes.add(shape::Capsule::default()),
meshes.add(shape::Torus::default()),
meshes.add(shape::Cylinder::default()),
meshes.add(Mesh::try_from(shape::Icosphere::default()).unwrap()),
meshes.add(shape::UVSphere::default()),
];

let num_shapes = shapes.len();
Expand Down Expand Up @@ -75,8 +75,8 @@ fn setup(

// ground plane
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.0).into()),
material: materials.add(Color::SILVER.into()),
mesh: meshes.add(shape::Plane::from_size(50.0)),
material: materials.add(Color::SILVER),
..default()
});

Expand Down
4 changes: 2 additions & 2 deletions examples/3d/3d_viewport_to_world.rs
Expand Up @@ -49,8 +49,8 @@ fn setup(
// plane
commands.spawn((
PbrBundle {
mesh: meshes.add(shape::Plane::from_size(20.).into()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(shape::Plane::from_size(20.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default()
},
Ground,
Expand Down
6 changes: 3 additions & 3 deletions examples/3d/anti_aliasing.rs
Expand Up @@ -259,8 +259,8 @@ fn setup(
) {
// Plane
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.0).into()),
material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()),
mesh: meshes.add(shape::Plane::from_size(50.0)),
material: materials.add(Color::rgb(0.1, 0.2, 0.1)),
..default()
});

Expand All @@ -272,7 +272,7 @@ fn setup(
// Cubes
for i in 0..5 {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.25 })),
mesh: meshes.add(shape::Cube { size: 0.25 }),
material: cube_material.clone(),
transform: Transform::from_xyz(i as f32 * 0.25 - 1.0, 0.125, -i as f32 * 0.5),
..default()
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/atmospheric_fog.rs
Expand Up @@ -79,7 +79,7 @@ fn setup_terrain_scene(
// Sky
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::default())),
mesh: meshes.add(shape::Box::default()),
material: materials.add(StandardMaterial {
base_color: Color::hex("888888").unwrap(),
unlit: true,
Expand Down
6 changes: 3 additions & 3 deletions examples/3d/blend_modes.rs
Expand Up @@ -146,10 +146,10 @@ fn setup(
.id();

// Chessboard Plane
let black_material = materials.add(Color::BLACK.into());
let white_material = materials.add(Color::WHITE.into());
let black_material = materials.add(Color::BLACK);
let white_material = materials.add(Color::WHITE);

let plane_mesh = meshes.add(shape::Plane::from_size(2.0).into());
let plane_mesh = meshes.add(shape::Plane::from_size(2.0));

for x in -3..4 {
for z in -3..4 {
Expand Down
5 changes: 2 additions & 3 deletions examples/3d/bloom_3d.rs
Expand Up @@ -56,11 +56,10 @@ fn setup_scene(
});

let mesh = meshes.add(
shape::Icosphere {
Mesh::try_from(shape::Icosphere {
radius: 0.5,
subdivisions: 5,
}
.try_into()
})
.unwrap(),
);

Expand Down
10 changes: 5 additions & 5 deletions examples/3d/deferred_rendering.rs
Expand Up @@ -103,16 +103,16 @@ fn setup(

// Plane
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(50.0).into()),
mesh: meshes.add(shape::Plane::from_size(50.0)),
material: forward_mat_h.clone(),
..default()
});

let cube_h = meshes.add(Mesh::from(shape::Cube { size: 0.1 }));
let sphere_h = meshes.add(Mesh::from(shape::UVSphere {
let cube_h = meshes.add(shape::Cube { size: 0.1 });
let sphere_h = meshes.add(shape::UVSphere {
radius: 0.125,
..default()
}));
});

// Cubes
commands.spawn(PbrBundle {
Expand Down Expand Up @@ -196,7 +196,7 @@ fn setup(
// sky
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::default())),
mesh: meshes.add(shape::Box::default()),
material: materials.add(StandardMaterial {
base_color: Color::hex("888888").unwrap(),
unlit: true,
Expand Down
10 changes: 5 additions & 5 deletions examples/3d/fog.rs
Expand Up @@ -58,14 +58,14 @@ fn setup_pyramid_scene(
// pillars
for (x, z) in &[(-1.5, -1.5), (1.5, -1.5), (1.5, 1.5), (-1.5, 1.5)] {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box {
mesh: meshes.add(shape::Box {
min_x: -0.5,
max_x: 0.5,
min_z: -0.5,
max_z: 0.5,
min_y: 0.0,
max_y: 3.0,
})),
}),
material: stone.clone(),
transform: Transform::from_xyz(*x, 0.0, *z),
..default()
Expand Down Expand Up @@ -97,14 +97,14 @@ fn setup_pyramid_scene(
let size = i as f32 / 2.0 + 3.0;
let y = -i as f32 / 2.0;
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box {
mesh: meshes.add(shape::Box {
min_x: -size,
max_x: size,
min_z: -size,
max_z: size,
min_y: 0.0,
max_y: 0.5,
})),
}),
material: stone.clone(),
transform: Transform::from_xyz(0.0, y, 0.0),
..default()
Expand All @@ -113,7 +113,7 @@ fn setup_pyramid_scene(

// sky
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::default())),
mesh: meshes.add(shape::Box::default()),
material: materials.add(StandardMaterial {
base_color: Color::hex("888888").unwrap(),
unlit: true,
Expand Down