@@ -289,12 +289,18 @@ impl<T: Sized> CassPtr<T, (Borrowed, Const)> {
289
289
}
290
290
}
291
291
292
+ mod own_sealed {
293
+ pub trait ExclusiveSealed { }
294
+ pub trait SharedSealed { }
295
+ pub trait BorrowedSealed { }
296
+ }
297
+
292
298
/// Defines a pointer manipulation API for non-shared heap-allocated data.
293
299
///
294
300
/// Implement this trait for types that are allocated by the driver via [`Box::new`],
295
301
/// and then returned to the user as a pointer. The user is responsible for freeing
296
302
/// the memory associated with the pointer using corresponding driver's API function.
297
- pub trait BoxFFI : Sized {
303
+ pub trait BoxFFI : Sized + own_sealed :: ExclusiveSealed {
298
304
fn into_ptr < M : Mutability > ( self : Box < Self > ) -> CassExclusivePtr < Self , M > {
299
305
CassExclusivePtr :: new ( self )
300
306
}
@@ -325,7 +331,7 @@ pub trait BoxFFI: Sized {
325
331
/// The data should be allocated via [`Arc::new`], and then returned to the user as a pointer.
326
332
/// The user is responsible for freeing the memory associated
327
333
/// with the pointer using corresponding driver's API function.
328
- pub trait ArcFFI : Sized {
334
+ pub trait ArcFFI : Sized + own_sealed :: SharedSealed {
329
335
fn as_ptr ( self : & Arc < Self > ) -> CassSharedPtr < Self > {
330
336
CassSharedPtr :: from_ref ( self )
331
337
}
@@ -360,7 +366,7 @@ pub trait ArcFFI: Sized {
360
366
/// For example: lifetime of CassRow is bound by the lifetime of CassResult.
361
367
/// There is no API function that frees the CassRow. It should be automatically
362
368
/// freed when user calls cass_result_free.
363
- pub trait RefFFI : Sized {
369
+ pub trait RefFFI : Sized + own_sealed :: BorrowedSealed {
364
370
fn as_ptr ( & self ) -> CassBorrowedPtr < Self > {
365
371
CassBorrowedPtr :: from_ref ( self )
366
372
}
@@ -374,3 +380,19 @@ pub trait RefFFI: Sized {
374
380
ptr. is_null ( )
375
381
}
376
382
}
383
+
384
+ pub trait FFI {
385
+ type Ownerhsip ;
386
+ }
387
+
388
+ pub struct OwnershipExclusive ;
389
+ impl < T > own_sealed:: ExclusiveSealed for T where T : FFI < Ownerhsip = OwnershipExclusive > { }
390
+ impl < T > BoxFFI for T where T : FFI < Ownerhsip = OwnershipExclusive > { }
391
+
392
+ pub struct OwnershipShared ;
393
+ impl < T > own_sealed:: SharedSealed for T where T : FFI < Ownerhsip = OwnershipShared > { }
394
+ impl < T > ArcFFI for T where T : FFI < Ownerhsip = OwnershipShared > { }
395
+
396
+ pub struct OwnershipBorrowed ;
397
+ impl < T > own_sealed:: BorrowedSealed for T where T : FFI < Ownerhsip = OwnershipBorrowed > { }
398
+ impl < T > RefFFI for T where T : FFI < Ownerhsip = OwnershipBorrowed > { }
0 commit comments