Skip to content

Commit cc96860

Browse files
bors[bot]Bromeon
andauthored
Merge #809
809: Relax Dictionary bound for keys: ToVariant -> OwnedToVariant r=Bromeon a=Bromeon Fixes #752 bors try Co-authored-by: Jan Haller <[email protected]>
2 parents 8c5cda8 + b5b40d0 commit cc96860

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

gdnative-core/src/core_types/dictionary.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
use std::iter::{Extend, FromIterator};
22
use std::marker::PhantomData;
33

4-
use crate::core_types::GodotString;
54
use crate::private::get_api;
65
use crate::sys;
76

8-
use crate::core_types::OwnedToVariant;
9-
use crate::core_types::ToVariant;
10-
use crate::core_types::ToVariantEq;
11-
use crate::core_types::Variant;
12-
use crate::core_types::VariantArray;
7+
use crate::core_types::{GodotString, OwnedToVariant, ToVariantEq, Variant, VariantArray};
138
use crate::object::NewRef;
149
use std::fmt;
1510

@@ -56,9 +51,9 @@ impl<Access: ThreadAccess> Dictionary<Access> {
5651
#[inline]
5752
pub fn contains<K>(&self, key: K) -> bool
5853
where
59-
K: ToVariant + ToVariantEq,
54+
K: OwnedToVariant + ToVariantEq,
6055
{
61-
unsafe { (get_api().godot_dictionary_has)(self.sys(), key.to_variant().sys()) }
56+
unsafe { (get_api().godot_dictionary_has)(self.sys(), key.owned_to_variant().sys()) }
6257
}
6358

6459
/// Returns true if the `Dictionary` has all of the keys in the given array.
@@ -71,9 +66,9 @@ impl<Access: ThreadAccess> Dictionary<Access> {
7166
#[inline]
7267
pub fn get<K>(&self, key: K) -> Option<Variant>
7368
where
74-
K: ToVariant + ToVariantEq,
69+
K: OwnedToVariant + ToVariantEq,
7570
{
76-
let key = key.to_variant();
71+
let key = key.owned_to_variant();
7772
if self.contains(&key) {
7873
// This should never return the default Nil, but there isn't a safe way to otherwise check
7974
// if the entry exists in a single API call.
@@ -87,14 +82,14 @@ impl<Access: ThreadAccess> Dictionary<Access> {
8782
#[inline]
8883
pub fn get_or<K, D>(&self, key: K, default: D) -> Variant
8984
where
90-
K: ToVariant + ToVariantEq,
91-
D: ToVariant,
85+
K: OwnedToVariant + ToVariantEq,
86+
D: OwnedToVariant,
9287
{
9388
unsafe {
9489
Variant((get_api().godot_dictionary_get_with_default)(
9590
self.sys(),
96-
key.to_variant().sys(),
97-
default.to_variant().sys(),
91+
key.owned_to_variant().sys(),
92+
default.owned_to_variant().sys(),
9893
))
9994
}
10095
}
@@ -104,7 +99,7 @@ impl<Access: ThreadAccess> Dictionary<Access> {
10499
#[inline]
105100
pub fn get_or_nil<K>(&self, key: K) -> Variant
106101
where
107-
K: ToVariant + ToVariantEq,
102+
K: OwnedToVariant + ToVariantEq,
108103
{
109104
self.get_or(key, Variant::new())
110105
}
@@ -117,10 +112,10 @@ impl<Access: ThreadAccess> Dictionary<Access> {
117112
#[inline]
118113
pub fn update<K, V>(&self, key: K, val: V)
119114
where
120-
K: ToVariant + ToVariantEq,
115+
K: OwnedToVariant + ToVariantEq,
121116
V: OwnedToVariant,
122117
{
123-
let key = key.to_variant();
118+
let key = key.owned_to_variant();
124119
assert!(self.contains(&key), "Can only update entries that exist");
125120

126121
unsafe {
@@ -145,11 +140,11 @@ impl<Access: ThreadAccess> Dictionary<Access> {
145140
#[inline]
146141
pub unsafe fn get_ref<K>(&self, key: K) -> &Variant
147142
where
148-
K: ToVariant + ToVariantEq,
143+
K: OwnedToVariant + ToVariantEq,
149144
{
150145
Variant::cast_ref((get_api().godot_dictionary_operator_index_const)(
151146
self.sys(),
152-
key.to_variant().sys(),
147+
key.owned_to_variant().sys(),
153148
))
154149
}
155150

@@ -167,11 +162,11 @@ impl<Access: ThreadAccess> Dictionary<Access> {
167162
#[allow(clippy::mut_from_ref)]
168163
pub unsafe fn get_mut_ref<K>(&self, key: K) -> &mut Variant
169164
where
170-
K: ToVariant + ToVariantEq,
165+
K: OwnedToVariant + ToVariantEq,
171166
{
172167
Variant::cast_mut_ref((get_api().godot_dictionary_operator_index)(
173168
self.sys_mut(),
174-
key.to_variant().sys(),
169+
key.owned_to_variant().sys(),
175170
))
176171
}
177172

@@ -308,9 +303,9 @@ impl<Access: LocalThreadAccess> Dictionary<Access> {
308303
#[inline]
309304
pub fn erase<K>(&self, key: K)
310305
where
311-
K: ToVariant + ToVariantEq,
306+
K: OwnedToVariant + ToVariantEq,
312307
{
313-
unsafe { (get_api().godot_dictionary_erase)(self.sys_mut(), key.to_variant().sys()) }
308+
unsafe { (get_api().godot_dictionary_erase)(self.sys_mut(), key.owned_to_variant().sys()) }
314309
}
315310

316311
/// Clears the `Dictionary`, removing all key-value pairs.

0 commit comments

Comments
 (0)