@@ -140,7 +140,7 @@ unsafe extern "C" fn c_database_change_listener(
140
140
c_doc_ids : * mut FLString ,
141
141
) {
142
142
let callback = context as * const DatabaseChangeListener ;
143
- let database = Database :: retain ( db as * mut CBLDatabase ) ;
143
+ let database = Database :: reference ( db as * mut CBLDatabase ) ;
144
144
145
145
let doc_ids = std:: slice:: from_raw_parts ( c_doc_ids, num_docs as usize )
146
146
. iter ( )
@@ -159,7 +159,7 @@ unsafe extern "C" fn c_database_buffer_notifications(
159
159
) {
160
160
let callback: BufferNotifications = std:: mem:: transmute ( context) ;
161
161
162
- let database = Database :: retain ( db. cast :: < CBLDatabase > ( ) ) ;
162
+ let database = Database :: reference ( db. cast :: < CBLDatabase > ( ) ) ;
163
163
164
164
callback ( & database) ;
165
165
}
@@ -180,15 +180,15 @@ impl CblRef for Database {
180
180
impl Database {
181
181
//////// CONSTRUCTORS:
182
182
183
- /// Takes ownership of the object and increase it's reference counter .
184
- pub ( crate ) fn retain ( cbl_ref : * mut CBLDatabase ) -> Self {
183
+ /// Increase the reference counter of the CBL ref, so dropping the instance will NOT free the ref .
184
+ pub ( crate ) fn reference ( cbl_ref : * mut CBLDatabase ) -> Self {
185
185
Self {
186
186
cbl_ref : unsafe { retain ( cbl_ref) } ,
187
187
}
188
188
}
189
189
190
- /// References the object without taking ownership and increasing it's reference counter
191
- pub ( crate ) const fn wrap ( cbl_ref : * mut CBLDatabase ) -> Self {
190
+ /// Takes ownership of the CBL ref, the reference counter is not increased so dropping the instance will free the ref.
191
+ pub ( crate ) const fn take_ownership ( cbl_ref : * mut CBLDatabase ) -> Self {
192
192
Self { cbl_ref }
193
193
}
194
194
@@ -217,7 +217,7 @@ impl Database {
217
217
if db_ref. is_null ( ) {
218
218
return failure ( err) ;
219
219
}
220
- Ok ( Self :: wrap ( db_ref) )
220
+ Ok ( Self :: take_ownership ( db_ref) )
221
221
}
222
222
223
223
//////// OTHER STATIC METHODS:
@@ -418,7 +418,7 @@ impl Database {
418
418
if scope. is_null ( ) {
419
419
None
420
420
} else {
421
- Some ( Scope :: wrap ( scope) )
421
+ Some ( Scope :: take_ownership ( scope) )
422
422
}
423
423
} )
424
424
}
@@ -445,7 +445,7 @@ impl Database {
445
445
if collection. is_null ( ) {
446
446
None
447
447
} else {
448
- Some ( Collection :: wrap ( collection) )
448
+ Some ( Collection :: take_ownership ( collection) )
449
449
}
450
450
} )
451
451
}
@@ -474,7 +474,7 @@ impl Database {
474
474
)
475
475
} ;
476
476
477
- check_error ( & error) . map ( |( ) | Collection :: wrap ( collection) )
477
+ check_error ( & error) . map ( |( ) | Collection :: take_ownership ( collection) )
478
478
}
479
479
480
480
/// Delete an existing collection.
@@ -499,7 +499,7 @@ impl Database {
499
499
let mut error = CBLError :: default ( ) ;
500
500
let scope = unsafe { CBLDatabase_DefaultScope ( self . get_ref ( ) , & mut error) } ;
501
501
502
- check_error ( & error) . map ( |( ) | Scope :: wrap ( scope) )
502
+ check_error ( & error) . map ( |( ) | Scope :: take_ownership ( scope) )
503
503
}
504
504
505
505
/// Returns the default collection.
@@ -511,7 +511,7 @@ impl Database {
511
511
if collection. is_null ( ) {
512
512
None
513
513
} else {
514
- Some ( Collection :: wrap ( collection) )
514
+ Some ( Collection :: take_ownership ( collection) )
515
515
}
516
516
} )
517
517
}
@@ -526,7 +526,7 @@ impl Database {
526
526
if collection. is_null ( ) {
527
527
Err ( Error :: cbl_error ( CouchbaseLiteError :: NotFound ) )
528
528
} else {
529
- Ok ( Collection :: wrap ( collection) )
529
+ Ok ( Collection :: take_ownership ( collection) )
530
530
}
531
531
}
532
532
@@ -596,6 +596,6 @@ impl Drop for Database {
596
596
597
597
impl Clone for Database {
598
598
fn clone ( & self ) -> Self {
599
- Self :: retain ( self . get_ref ( ) )
599
+ Self :: reference ( self . get_ref ( ) )
600
600
}
601
601
}
0 commit comments