Skip to content

Commit 4d96a95

Browse files
committed
Rename ThreadAccess -> Ownership
1 parent 796a07f commit 4d96a95

File tree

9 files changed

+176
-172
lines changed

9 files changed

+176
-172
lines changed

bindings_generator/src/documentation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ This class is used to interact with Godot's editor."#
129129
All types in the Godot API have _interior mutability_ in Rust parlance.
130130
To enforce that the official [thread-safety guidelines][thread-safety] are
131131
followed, the typestate pattern is used in the `Ref` and `TRef` smart pointers,
132-
and the `Instance` API. The typestate `Access` in these types tracks whether the
133-
access is unique, shared, or exclusive to the current thread. For more information,
132+
and the `Instance` API. The typestate `Ownership` in these types tracks whether
133+
ownership is unique, shared, or exclusive to the current thread. For more information,
134134
see the type-level documentation on `Ref`.
135135
136136
[thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html"#;

gdnative-core/src/core_types/dictionary.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ use crate::object::ownership::*;
2020
///
2121
/// This is a reference-counted collection with "interior mutability" in Rust parlance.
2222
/// To enforce that the official [thread-safety guidelines][thread-safety] are
23-
/// followed this type uses the *typestate* pattern. The typestate `Access` tracks
23+
/// followed this type uses the *typestate* pattern. The typestate `Ownership` tracks
2424
/// whether there is thread-local or unique access (where pretty much all operations are safe)
2525
/// or whether the value might be "shared", in which case not all operations are
2626
/// safe.
2727
///
2828
/// [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
29-
pub struct Dictionary<Access: ThreadAccess = Shared> {
29+
pub struct Dictionary<Own: Ownership = Shared> {
3030
sys: sys::godot_dictionary,
3131

3232
/// Marker preventing the compiler from incorrectly deriving `Send` and `Sync`.
33-
_marker: PhantomData<Access>,
33+
_marker: PhantomData<Own>,
3434
}
3535

3636
/// Operations allowed on all Dictionaries at any point in time.
37-
impl<Access: ThreadAccess> Dictionary<Access> {
37+
impl<Own: Ownership> Dictionary<Own> {
3838
/// Returns `true` if the `Dictionary` contains no elements.
3939
#[inline]
4040
pub fn is_empty(&self) -> bool {
@@ -58,7 +58,7 @@ impl<Access: ThreadAccess> Dictionary<Access> {
5858

5959
/// Returns true if the `Dictionary` has all of the keys in the given array.
6060
#[inline]
61-
pub fn contains_all<ArrAccess: ThreadAccess>(&self, keys: &VariantArray<ArrAccess>) -> bool {
61+
pub fn contains_all<ArrayOws: Ownership>(&self, keys: &VariantArray<ArrayOws>) -> bool {
6262
unsafe { (get_api().godot_dictionary_has_all)(self.sys(), keys.sys()) }
6363
}
6464

@@ -200,7 +200,7 @@ impl<Access: ThreadAccess> Dictionary<Access> {
200200
/// Modifying the same underlying collection while observing the safety assumptions will
201201
/// not violate memory safely, but may lead to surprising behavior in the iterator.
202202
#[inline]
203-
pub fn iter(&self) -> Iter<Access> {
203+
pub fn iter(&self) -> Iter<Own> {
204204
Iter::new(self)
205205
}
206206

@@ -238,7 +238,7 @@ impl<Access: ThreadAccess> Dictionary<Access> {
238238
}
239239
}
240240

241-
unsafe fn cast_access<A: ThreadAccess>(self) -> Dictionary<A> {
241+
unsafe fn cast_access<A: Ownership>(self) -> Dictionary<A> {
242242
let sys = self.sys;
243243
std::mem::forget(self);
244244
Dictionary::from_sys(sys)
@@ -264,7 +264,7 @@ impl Dictionary<ThreadLocal> {
264264
}
265265

266266
/// Operations allowed on Dictionaries that are not unique.
267-
impl<Access: NonUniqueThreadAccess> Dictionary<Access> {
267+
impl<Own: NonUniqueOwnership> Dictionary<Own> {
268268
/// Assume that this is the only reference to this dictionary, on which
269269
/// operations that change the container size can be safely performed.
270270
///
@@ -282,7 +282,7 @@ impl<Access: NonUniqueThreadAccess> Dictionary<Access> {
282282
}
283283

284284
/// Operations allowed on Dictionaries that can only be referenced to from the current thread.
285-
impl<Access: LocalThreadAccess> Dictionary<Access> {
285+
impl<Own: LocalThreadOwnership> Dictionary<Own> {
286286
#[inline]
287287
/// Inserts or updates the value of the element corresponding to the key.
288288
pub fn insert<K, V>(&self, key: K, val: V)
@@ -340,7 +340,7 @@ impl Dictionary<Unique> {
340340
}
341341
}
342342

343-
impl<Access: ThreadAccess> Drop for Dictionary<Access> {
343+
impl<Own: Ownership> Drop for Dictionary<Own> {
344344
#[inline]
345345
fn drop(&mut self) {
346346
unsafe { (get_api().godot_dictionary_destroy)(self.sys_mut()) }
@@ -368,7 +368,7 @@ impl Default for Dictionary<ThreadLocal> {
368368
}
369369
}
370370

371-
impl<Access: NonUniqueThreadAccess> NewRef for Dictionary<Access> {
371+
impl<Own: NonUniqueOwnership> NewRef for Dictionary<Own> {
372372
#[inline]
373373
fn new_ref(&self) -> Self {
374374
unsafe {
@@ -393,15 +393,15 @@ impl From<Dictionary<Unique>> for Dictionary<ThreadLocal> {
393393
}
394394
}
395395

396-
impl<Access: ThreadAccess> fmt::Debug for Dictionary<Access> {
396+
impl<Own: Ownership> fmt::Debug for Dictionary<Own> {
397397
#[inline]
398398
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
399399
self.to_json().to_string().fmt(f)
400400
}
401401
}
402402

403-
unsafe fn iter_next<Access: ThreadAccess>(
404-
dic: &Dictionary<Access>,
403+
unsafe fn iter_next<Own: Ownership>(
404+
dic: &Dictionary<Own>,
405405
last_key: &mut Option<Variant>,
406406
) -> Option<(Variant, Variant)> {
407407
let last_ptr = last_key.as_ref().map_or(std::ptr::null(), Variant::sys);
@@ -421,22 +421,22 @@ unsafe fn iter_next<Access: ThreadAccess>(
421421
///
422422
/// This struct is created by the `iter` method on `Dictionary<Unique>`.
423423
#[derive(Debug)]
424-
pub struct Iter<'a, Access: ThreadAccess> {
425-
dic: &'a Dictionary<Access>,
424+
pub struct Iter<'a, Own: Ownership> {
425+
dic: &'a Dictionary<Own>,
426426
last_key: Option<Variant>,
427427
}
428428

429-
impl<'a, Access: ThreadAccess> Iter<'a, Access> {
429+
impl<'a, Own: Ownership> Iter<'a, Own> {
430430
/// Create an Iterator from a unique Dictionary.
431-
fn new(dic: &'a Dictionary<Access>) -> Self {
431+
fn new(dic: &'a Dictionary<Own>) -> Self {
432432
Iter {
433433
dic,
434434
last_key: None,
435435
}
436436
}
437437
}
438438

439-
impl<'a, Access: ThreadAccess> Iterator for Iter<'a, Access> {
439+
impl<'a, Own: Ownership> Iterator for Iter<'a, Own> {
440440
type Item = (Variant, Variant);
441441

442442
#[inline]
@@ -451,9 +451,9 @@ impl<'a, Access: ThreadAccess> Iterator for Iter<'a, Access> {
451451
}
452452
}
453453

454-
impl<'a, Access: ThreadAccess> IntoIterator for &'a Dictionary<Access> {
454+
impl<'a, Own: Ownership> IntoIterator for &'a Dictionary<Own> {
455455
type Item = (Variant, Variant);
456-
type IntoIter = Iter<'a, Access>;
456+
type IntoIter = Iter<'a, Own>;
457457
#[inline]
458458
fn into_iter(self) -> Self::IntoIter {
459459
self.iter()
@@ -517,7 +517,7 @@ where
517517
}
518518
}
519519

520-
impl<K, V, Access: LocalThreadAccess> Extend<(K, V)> for Dictionary<Access>
520+
impl<K, V, Own: LocalThreadOwnership> Extend<(K, V)> for Dictionary<Own>
521521
where
522522
K: ToVariantEq + OwnedToVariant,
523523
V: OwnedToVariant,

gdnative-core/src/core_types/variant_array.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ use std::fmt;
3030
/// safe.
3131
///
3232
/// [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
33-
pub struct VariantArray<Access: ThreadAccess = Shared> {
33+
pub struct VariantArray<Own: Ownership = Shared> {
3434
sys: sys::godot_array,
3535

3636
/// Marker preventing the compiler from incorrectly deriving `Send` and `Sync`.
37-
_marker: PhantomData<Access>,
37+
_marker: PhantomData<Own>,
3838
}
3939

4040
/// Operations allowed on all arrays at any point in time.
41-
impl<Access: ThreadAccess> VariantArray<Access> {
41+
impl<Own: Ownership> VariantArray<Own> {
4242
/// Sets the value of the element at the given offset.
4343
#[inline]
4444
pub fn set<T: OwnedToVariant>(&self, idx: i32, val: T) {
@@ -177,7 +177,7 @@ impl<Access: ThreadAccess> VariantArray<Access> {
177177
/// Modifying the same underlying collection while observing the safety assumptions will
178178
/// not violate memory safely, but may lead to surprising behavior in the iterator.
179179
#[inline]
180-
pub fn iter(&self) -> Iter<'_, Access> {
180+
pub fn iter(&self) -> Iter<'_, Own> {
181181
self.into_iter()
182182
}
183183

@@ -217,7 +217,7 @@ impl<Access: ThreadAccess> VariantArray<Access> {
217217
}
218218
}
219219

220-
unsafe fn cast_access<A: ThreadAccess>(self) -> VariantArray<A> {
220+
unsafe fn cast_access<A: Ownership>(self) -> VariantArray<A> {
221221
let sys = self.sys;
222222
std::mem::forget(self);
223223
VariantArray::from_sys(sys)
@@ -234,7 +234,7 @@ impl<Access: ThreadAccess> VariantArray<Access> {
234234
}
235235

236236
/// Operations allowed on Dictionaries that can only be referenced to from the current thread.
237-
impl<Access: LocalThreadAccess> VariantArray<Access> {
237+
impl<Own: LocalThreadOwnership> VariantArray<Own> {
238238
/// Clears the array, resizing to 0.
239239
#[inline]
240240
pub fn clear(&self) {
@@ -297,7 +297,7 @@ impl<Access: LocalThreadAccess> VariantArray<Access> {
297297
}
298298

299299
/// Operations allowed on non-unique arrays.
300-
impl<Access: NonUniqueThreadAccess> VariantArray<Access> {
300+
impl<Own: NonUniqueOwnership> VariantArray<Own> {
301301
/// Assume that this is the only reference to this array, on which
302302
/// operations that change the container size can be safely performed.
303303
///
@@ -378,7 +378,7 @@ impl Default for VariantArray<ThreadLocal> {
378378
}
379379
}
380380

381-
impl<Access: NonUniqueThreadAccess> NewRef for VariantArray<Access> {
381+
impl<Own: NonUniqueOwnership> NewRef for VariantArray<Own> {
382382
#[inline]
383383
fn new_ref(&self) -> Self {
384384
unsafe {
@@ -389,27 +389,27 @@ impl<Access: NonUniqueThreadAccess> NewRef for VariantArray<Access> {
389389
}
390390
}
391391

392-
impl<Access: ThreadAccess> Drop for VariantArray<Access> {
392+
impl<Own: Ownership> Drop for VariantArray<Own> {
393393
#[inline]
394394
fn drop(&mut self) {
395395
unsafe { (get_api().godot_array_destroy)(self.sys_mut()) }
396396
}
397397
}
398398

399-
impl<Access: ThreadAccess> fmt::Debug for VariantArray<Access> {
399+
impl<Own: Ownership> fmt::Debug for VariantArray<Own> {
400400
#[inline]
401401
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
402402
f.debug_list().entries(self.iter()).finish()
403403
}
404404
}
405405

406406
// #[derive(Debug)]
407-
pub struct Iter<'a, Access: ThreadAccess> {
408-
arr: &'a VariantArray<Access>,
407+
pub struct Iter<'a, Own: Ownership> {
408+
arr: &'a VariantArray<Own>,
409409
range: std::ops::Range<i32>,
410410
}
411411

412-
impl<'a, Access: ThreadAccess> Iterator for Iter<'a, Access> {
412+
impl<'a, Own: Ownership> Iterator for Iter<'a, Own> {
413413
type Item = Variant;
414414

415415
#[inline]
@@ -444,9 +444,9 @@ impl<'a, Access: ThreadAccess> Iterator for Iter<'a, Access> {
444444
}
445445
}
446446

447-
impl<'a, Access: ThreadAccess> IntoIterator for &'a VariantArray<Access> {
447+
impl<'a, Own: Ownership> IntoIterator for &'a VariantArray<Own> {
448448
type Item = Variant;
449-
type IntoIter = Iter<'a, Access>;
449+
type IntoIter = Iter<'a, Own>;
450450
#[inline]
451451
fn into_iter(self) -> Self::IntoIter {
452452
Iter {
@@ -518,7 +518,7 @@ impl<T: ToVariant> FromIterator<T> for VariantArray<Unique> {
518518
}
519519
}
520520

521-
impl<T: ToVariant, Access: LocalThreadAccess> Extend<T> for VariantArray<Access> {
521+
impl<T: ToVariant, Own: LocalThreadOwnership> Extend<T> for VariantArray<Own> {
522522
#[inline]
523523
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
524524
for elem in iter {

gdnative-core/src/export/class.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::export::user_data::UserData;
22
use crate::export::ClassBuilder;
3-
use crate::object::ownership::{Shared, ThreadAccess, Unique};
3+
use crate::object::ownership::{Ownership, Shared, Unique};
44
use crate::object::{GodotObject, Instance, Instanciable, TRef};
55

66
/// Trait used for describing and initializing a Godot script class.
@@ -120,36 +120,36 @@ pub trait NativeClassMethods: NativeClass {
120120
/// undefined behavior.
121121
///
122122
/// [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
123-
pub trait OwnerArg<'a, T: GodotObject, Access: ThreadAccess + 'static>: private::Sealed {
123+
pub trait OwnerArg<'a, T: GodotObject, Own: Ownership + 'static>: private::Sealed {
124124
#[doc(hidden)]
125-
fn from_safe_ref(owner: TRef<'a, T, Access>) -> Self;
125+
fn from_safe_ref(owner: TRef<'a, T, Own>) -> Self;
126126
}
127127

128128
impl<'a, T> private::Sealed for &'a T where T: GodotObject {}
129-
impl<'a, T, Access> OwnerArg<'a, T, Access> for &'a T
129+
impl<'a, T, Own> OwnerArg<'a, T, Own> for &'a T
130130
where
131131
T: GodotObject,
132-
Access: ThreadAccess + 'static,
132+
Own: Ownership + 'static,
133133
{
134134
#[inline]
135-
fn from_safe_ref(owner: TRef<'a, T, Access>) -> Self {
135+
fn from_safe_ref(owner: TRef<'a, T, Own>) -> Self {
136136
owner.as_ref()
137137
}
138138
}
139139

140-
impl<'a, T, Access> private::Sealed for TRef<'a, T, Access>
140+
impl<'a, T, Own> private::Sealed for TRef<'a, T, Own>
141141
where
142142
T: GodotObject,
143-
Access: ThreadAccess + 'static,
143+
Own: Ownership + 'static,
144144
{
145145
}
146-
impl<'a, T, Access> OwnerArg<'a, T, Access> for TRef<'a, T, Access>
146+
impl<'a, T, Own> OwnerArg<'a, T, Own> for TRef<'a, T, Own>
147147
where
148148
T: GodotObject,
149-
Access: ThreadAccess + 'static,
149+
Own: Ownership + 'static,
150150
{
151151
#[inline]
152-
fn from_safe_ref(owner: TRef<'a, T, Access>) -> Self {
152+
fn from_safe_ref(owner: TRef<'a, T, Own>) -> Self {
153153
owner
154154
}
155155
}

gdnative-core/src/object/bounds.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,17 @@ impl<'a, 'r: 'a> LifetimeConstraint<RefCounted> for AssumeSafeLifetime<'a, 'r> {
217217

218218
/// Trait for combinations of `RefKind` and `ThreadAccess` that can be dereferenced safely.
219219
/// This is an internal interface.
220-
pub unsafe trait SafeDeref<Kind: RefKind, Access: ThreadAccess> {
220+
pub unsafe trait SafeDeref<Kind: RefKind, Own: Ownership> {
221221
/// Returns a safe reference to the underlying object.
222222
#[doc(hidden)]
223-
fn impl_as_ref<T: GodotObject<RefKind = Kind>>(this: &Ref<T, Access>) -> TRef<'_, T, Access>;
223+
fn impl_as_ref<T: GodotObject<RefKind = Kind>>(this: &Ref<T, Own>) -> TRef<'_, T, Own>;
224224
}
225225

226226
/// Trait for persistent `Ref`s that point to valid objects. This is an internal interface.
227-
pub unsafe trait SafeAsRaw<Kind: RefKind, Access: ThreadAccess> {
227+
pub unsafe trait SafeAsRaw<Kind: RefKind, Own: Ownership> {
228228
/// Returns a raw reference to the underlying object.
229229
#[doc(hidden)]
230-
fn impl_as_raw<T: GodotObject<RefKind = Kind>>(this: &Ref<T, Access>) -> &RawObject<T>;
230+
fn impl_as_raw<T: GodotObject<RefKind = Kind>>(this: &Ref<T, Own>) -> &RawObject<T>;
231231
}
232232

233233
// ----------------------------------------------------------------------------------------------------------------------------------------------
@@ -247,11 +247,9 @@ unsafe impl SafeDeref<ManuallyManaged, Unique> for RefImplBound {
247247
}
248248
}
249249

250-
unsafe impl<Access: LocalThreadAccess> SafeDeref<RefCounted, Access> for RefImplBound {
250+
unsafe impl<Own: LocalThreadOwnership> SafeDeref<RefCounted, Own> for RefImplBound {
251251
#[inline]
252-
fn impl_as_ref<T: GodotObject<RefKind = RefCounted>>(
253-
this: &Ref<T, Access>,
254-
) -> TRef<'_, T, Access> {
252+
fn impl_as_ref<T: GodotObject<RefKind = RefCounted>>(this: &Ref<T, Own>) -> TRef<'_, T, Own> {
255253
unsafe { this.assume_safe_unchecked() }
256254
}
257255
}
@@ -265,9 +263,9 @@ unsafe impl SafeAsRaw<ManuallyManaged, Unique> for RefImplBound {
265263
}
266264
}
267265

268-
unsafe impl<Access: ThreadAccess> SafeAsRaw<RefCounted, Access> for RefImplBound {
266+
unsafe impl<Own: Ownership> SafeAsRaw<RefCounted, Own> for RefImplBound {
269267
#[inline]
270-
fn impl_as_raw<T: GodotObject<RefKind = RefCounted>>(this: &Ref<T, Access>) -> &RawObject<T> {
268+
fn impl_as_raw<T: GodotObject<RefKind = RefCounted>>(this: &Ref<T, Own>) -> &RawObject<T> {
271269
unsafe { this.as_raw_unchecked() }
272270
}
273271
}

0 commit comments

Comments
 (0)