Skip to content

Commit 9312a1b

Browse files
authored
Allow bsn! scene inheritance to use paths with generics (#23902)
# Objective support generics in `bsn!` scene inheritance syntax (i.e. `:some_scene::<T>`) ## Solution Parse `Path` instead of an `Ident` for scene inheritance ## Testing added `inheritance_with_generics` test to `bevy_scene/src/lib.rs`
1 parent f135b2b commit 9312a1b

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

crates/bevy_scene/macros/src/bsn/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl BsnInheritedScene {
224224
let path = input.parse::<LitStr>()?;
225225
BsnInheritedScene::Asset(path)
226226
} else {
227-
let function = input.parse::<Ident>()?;
227+
let function = input.parse::<Path>()?;
228228
let args = if input.peek(Paren) {
229229
let content;
230230
parenthesized!(content in input);

crates/bevy_scene/macros/src/bsn/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub enum BsnSceneListItem {
5555
pub enum BsnInheritedScene {
5656
Asset(LitStr),
5757
Fn {
58-
function: Ident,
58+
function: Path,
5959
args: Option<Punctuated<Expr, Token![,]>>,
6060
},
6161
}

crates/bevy_scene/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,4 +1423,36 @@ mod tests {
14231423

14241424
panic!("Ran out of loops to return `Some` from `predicate`");
14251425
}
1426+
1427+
#[test]
1428+
fn inheritance_with_generics() {
1429+
#[derive(Component, FromTemplate, PartialEq, Eq, Debug)]
1430+
struct Foo<T: FromTemplate<Template: Default + Template<Output = T>>> {
1431+
value: T,
1432+
number: u32,
1433+
}
1434+
1435+
fn b() -> impl Scene {
1436+
bsn! {
1437+
:a::<0, i32>
1438+
Children [ #Y ]
1439+
}
1440+
}
1441+
1442+
fn a<
1443+
const A: u32,
1444+
T: 'static
1445+
+ Send
1446+
+ Sync
1447+
+ FromTemplate<Template: Send + Sync + Default + Template<Output = T>>,
1448+
>() -> impl Scene {
1449+
bsn! {
1450+
Foo<T>{
1451+
number: A
1452+
}
1453+
}
1454+
}
1455+
1456+
b();
1457+
}
14261458
}

0 commit comments

Comments
 (0)