@@ -72,6 +72,14 @@ impl<Access: ThreadAccess> Dictionary<Access> {
72
72
/// Returns a copy of the value corresponding to the key.
73
73
#[ inline]
74
74
pub fn get < K > ( & self , key : K ) -> Variant
75
+ where
76
+ K : ToVariant + ToVariantEq ,
77
+ {
78
+ self . get_or ( Variant :: new ( ) , key)
79
+ }
80
+
81
+ #[ inline]
82
+ pub fn get_or_insert_default < K > ( & self , key : K ) -> Variant
75
83
where
76
84
K : ToVariant + ToVariantEq ,
77
85
{
@@ -83,6 +91,36 @@ impl<Access: ThreadAccess> Dictionary<Access> {
83
91
}
84
92
}
85
93
94
+ /// Returns a copy of the value corresponding to the key, or `default` if it doesn't exist
95
+ #[ inline]
96
+ pub fn get_or < K , D > ( & self , default : D , key : K ) -> Variant
97
+ where
98
+ K : ToVariant + ToVariantEq ,
99
+ D : ToVariant + ToVariantEq ,
100
+ {
101
+ unsafe {
102
+ Variant ( ( get_api ( ) . godot_dictionary_get_with_default ) (
103
+ self . sys ( ) ,
104
+ key. to_variant ( ) . sys ( ) ,
105
+ default. to_variant ( ) . sys ( ) ,
106
+ ) )
107
+ }
108
+ }
109
+
110
+ /// Returns a copy of the value corresponding to the key if it exists and is not `Nil`, or `None` otherwise
111
+ #[ inline]
112
+ pub fn get_or_none < K > ( & self , key : K ) -> Option < Variant >
113
+ where
114
+ K : ToVariant + ToVariantEq ,
115
+ {
116
+ let result = self . get ( key) ;
117
+ if result. is_nil ( ) {
118
+ None
119
+ } else {
120
+ Some ( result)
121
+ }
122
+ }
123
+
86
124
/// Update an existing element corresponding ot the key.
87
125
///
88
126
/// # Panics
0 commit comments