Comments (5)
@adamreichold Any idea how to solve that? I was hoping to get the result with the lifetime of owner
. Thanks!
from kohonen.
Any idea how to solve that? I was hoping to get the result with the lifetime of
owner
. Thanks!
I think the first attempt should be to drop the lifetime all together and pass owner
by value. It already is a pointer to an object whose life time is managed by Godot. (Which is the reason why all actual accesses are unsafe.)
The second observation would be that you probably have to pass the full Instance<Kohonen>
around as the Godot object part of it controls the life time even though you are only interested in the native class part.
(More specifically, the signature fn Instance::map<F, U>(&self, op: F)
with F: for<'a>: FnOnce(&'a T, <T as NativeClass>::Base) -> U
informs you that you loose any control over the lifetime of the &'a T
pass to you and hence its scope is effectively limited to your calling scope.)
Long story short: Rust lifetimes will probably not help much when interacting with objects managed by Godots runtime are they are currently exposed which explains the huge amount of unsafe functions in its API.
from kohonen.
Meaning that your signature should probably just be fn get_kohonen(owner: gdnative::Node2D) -> Option<Instance<Kohonen>>
. (I don't think you actually need &self
here?)
from kohonen.
@adamreichold Thanks!
So far, I solved it by a function taking a closure, so I don't need to care for lifetimes:
trait KohonenUser2D {
fn with_kohonen<F>(mut owner: gdnative::Control, path: &str, mut fun: F)
where
F: FnMut(&mut gdnative::Control, &Kohonen),
{
let node = unsafe { owner.get_node(NodePath::from_str(path)) };
node.and_then(|node| {
Instance::<Kohonen>::try_from_base(node)
.map(|inst| inst.map(|koh, _| fun(&mut owner, koh)))
});
}
}
from kohonen.
@adamreichold Thanks!
So far, I solved it by a function taking a closure, so I don't need to care for lifetimes:
Closure-based are often the last resort when fixing lifetime issue due to the implicit HKTB on the closure types FnOnce
, Fn
and FnMut
. Keep in mind that fetch the node via get_node
is not particularly cheap and even NodePath::from_str
will allocate.
from kohonen.
Related Issues (8)
- SOM & units to file. HOT 1
- Prediction: apply trained SOM to data.
- Label propagation for semi-supervised learing
- Scripting for filtering and transforming training data
- [Feature] Add progress indicator / progress bar
- [Feature] PLSOM implementation (The Parameterless Self-Organizing Map Algorithm)
- [Feature] Bi-directional SOM implementation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kohonen.