Skip to content

impl SceneList for Vec<Box<dyn SceneList>>#24242

Open
chronicl wants to merge 1 commit into
bevyengine:mainfrom
chronicl:scene_list_vec
Open

impl SceneList for Vec<Box<dyn SceneList>>#24242
chronicl wants to merge 1 commit into
bevyengine:mainfrom
chronicl:scene_list_vec

Conversation

@chronicl
Copy link
Copy Markdown
Contributor

@chronicl chronicl commented May 11, 2026

Objective

I couldn't figure out a way to spawn a variable amount of SceneLists as Children.

This came up when trying to make a variable row grid layout, each row being a SceneList because it has columns that need to be inserted directly into the grid Node:

let rows: Vec<Box<dyn SceneList>> = ...;
bsn! {
    Node { display: Display::Grid }
    // This doesn't work
    Children [ { rows } ]
}

Solution

impl SceneList for Vec<Box<dyn SceneList>> { ... }

This can be implemented in user land by creating a wrapper type for Vec<Box<dyn SceneList>>, so I don't feel strongly about actually merging this PR.

Testing

None so far.

@chronicl
Copy link
Copy Markdown
Contributor Author

Actually, a better solution that can avoid Boxing if the SceneList types are homogenous is to create a

#[derive(Deref, DerefMut)]
struct VecSceneList<S>(pub Vec<S>);

impl<S: SceneList> SceneList for VecSceneList<S> { ... }

// Convenience method for when the `SceneList` types aren't homogenous (and thus Box is required)
impl VecSceneList<Box<dyn SceneList>> {
    fn push_box(&mut self, scene_list: impl SceneList) { self.push(Box::new(scene_list) }
}

but this can be implemented in user land. I'm not sure if bevy wants to provide these kind of helper types?

@villejuutila
Copy link
Copy Markdown

It should be possible to pass Vec<impl Scene> for Children already.

@chronicl
Copy link
Copy Markdown
Contributor Author

chronicl commented May 11, 2026

It should be possible to pass Vec<impl Scene> for Children already.

I need Vec<impl SceneList> to implement SceneList (not Vec<impl Scene>), which is trivial to implement, however

// We already have
impl<S: Scene> SceneList for Vec<S>
// so we can't also have
impl<S: SceneList> SceneList for Vec<S>
// because there could be types that are S: Scene + SceneList and rust doesn't have specialization

@kfc35 kfc35 added A-Scenes Composing and serializing ECS objects S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Straightforward Simple bug fixes and API improvements, docs, test and examples C-Usability A targeted quality-of-life change that makes Bevy easier to use labels May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Composing and serializing ECS objects C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants