Trying to get a sibling node as Rust struct. Scene:
Node
|- Kohonen
'- Mapping
use crate::Kohonen;
use gdnative::{Instance, Node2D, NodePath};
#[derive(gdnative::NativeClass)]
#[inherit(gdnative::Node2D)]
pub struct Mapping;
#[gdnative::methods]
impl Mapping {
fn _init(_owner: gdnative::Node2D) -> Self {
Mapping
}
#[export]
fn _ready(&mut self, owner: gdnative::Node2D) {}
#[export]
pub fn _process(&mut self, owner: Node2D, _delta: f64) {}
fn get_kohonen<'a>(&self, owner: &'a gdnative::Node2D) -> Option<&'a Kohonen> {
let node = unsafe { owner.get_node(NodePath::from_str("../Kohonen")) };
let koh: Option<&'a Kohonen> = node.and_then(|node| {
Instance::<Kohonen>::try_from_base(node).map(|inst| inst.map(|koh, _| koh).unwrap())
});
koh
}
}
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> kohvis\src\mapping_gd.rs:23:83
|
23 | Instance::<Kohonen>::try_from_base(node).map(|inst| inst.map(|koh, _| koh).unwrap())
| ^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 23:74...
--> kohvis\src\mapping_gd.rs:23:74
|
23 | Instance::<Kohonen>::try_from_base(node).map(|inst| inst.map(|koh, _| koh).unwrap())
| ^^^^^^^^^^^^
note: ...so that the expression is assignable
--> kohvis\src\mapping_gd.rs:23:83
|
23 | Instance::<Kohonen>::try_from_base(node).map(|inst| inst.map(|koh, _| koh).unwrap())
| ^^^
= note: expected `&kohonen_gd::Kohonen`
found `&kohonen_gd::Kohonen`
note: but, the lifetime must be valid for the lifetime `'a` as defined on the method body at 20:20...
--> kohvis\src\mapping_gd.rs:20:20
|
20 | fn get_kohonen<'a>(&self, owner: &'a gdnative::Node2D) -> Option<&'a Kohonen> {
| ^^
note: ...so that the expression is assignable
--> kohvis\src\mapping_gd.rs:22:40
|
22 | let koh: Option<&'a Kohonen> = node.and_then(|node| {
| ________________________________________^
23 | | Instance::<Kohonen>::try_from_base(node).map(|inst| inst.map(|koh, _| koh).unwrap())
24 | | });
| |__________^
= note: expected `std::option::Option<&'a kohonen_gd::Kohonen>`
found `std::option::Option<&kohonen_gd::Kohonen>`
error: aborting due to previous error