1
1
//! Utility functions and extension traits that depend on generated bindings
2
2
3
+ use gdnative_core:: core_types:: NodePath ;
3
4
use gdnative_core:: export:: NativeClass ;
4
5
use gdnative_core:: object:: { SubClass , TInstance , TRef } ;
5
6
30
31
. cast :: < T > ( )
31
32
}
32
33
33
- pub trait NodeExt {
34
+ pub trait NodeResolveExt < P : Into < NodePath > > {
34
35
/// Convenience method to obtain a reference to a node at `path` relative to `self`,
35
36
/// and cast it to the desired type. Returns `None` if the node does not exist or is
36
37
/// not of the correct type.
@@ -42,7 +43,7 @@ pub trait NodeExt {
42
43
/// invariants must be observed for the resulting node during `'a`, if any.
43
44
///
44
45
/// [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
45
- unsafe fn get_node_as < ' a , T > ( & self , path : & str ) -> Option < TRef < ' a , T > >
46
+ unsafe fn get_node_as < ' a , T > ( & self , path : P ) -> Option < TRef < ' a , T > >
46
47
where
47
48
T : SubClass < Node > ;
48
49
@@ -57,7 +58,7 @@ pub trait NodeExt {
57
58
/// invariants must be observed for the resulting node during `'a`, if any.
58
59
///
59
60
/// [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
60
- unsafe fn get_node_as_instance < ' a , T > ( & self , path : & str ) -> Option < TInstance < ' a , T > >
61
+ unsafe fn get_node_as_instance < ' a , T > ( & self , path : P ) -> Option < TInstance < ' a , T > >
61
62
where
62
63
T : NativeClass ,
63
64
T :: Base : SubClass < Node > ,
@@ -66,20 +67,11 @@ pub trait NodeExt {
66
67
}
67
68
}
68
69
69
- impl < ' n , N : SubClass < Node > > NodeExt for & ' n N {
70
- unsafe fn get_node_as < ' a , T > ( & self , path : & str ) -> Option < TRef < ' a , T > >
70
+ impl < N : SubClass < Node > , P : Into < NodePath > > NodeResolveExt < P > for N {
71
+ unsafe fn get_node_as < ' a , T > ( & self , path : P ) -> Option < TRef < ' a , T > >
71
72
where
72
73
T : SubClass < Node > ,
73
74
{
74
75
self . upcast ( ) . get_node ( path) ?. assume_safe ( ) . cast ( )
75
76
}
76
77
}
77
-
78
- impl < ' n , N : SubClass < Node > > NodeExt for TRef < ' n , N > {
79
- unsafe fn get_node_as < ' a , T > ( & self , path : & str ) -> Option < TRef < ' a , T > >
80
- where
81
- T : SubClass < Node > ,
82
- {
83
- self . as_ref ( ) . get_node_as ( path)
84
- }
85
- }
0 commit comments