Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit a5c6546

Browse files
committed
Add support for creating abstract subclasses
1 parent fe523ef commit a5c6546

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/subclass/types.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ pub trait ObjectSubclass: ObjectImpl + Sized + 'static {
236236
/// This must be unique in the whole process.
237237
const NAME: &'static str;
238238

239+
/// If this subclass is an abstract class or not.
240+
///
241+
/// By default all subclasses are non-abstract types but setting this to `true` will create an
242+
/// abstract class instead.
243+
///
244+
/// Abstract classes can't be instantiated and require a non-abstract subclass.
245+
///
246+
/// Optional.
247+
const ABSTRACT: bool = false;
248+
239249
/// Parent Rust type to inherit from.
240250
type ParentType: ObjectType
241251
+ FromGlibPtrBorrow<*mut <Self::ParentType as ObjectType>::GlibType>
@@ -470,7 +480,11 @@ where
470480
<T::ParentType as StaticType>::static_type().to_glib(),
471481
type_name.as_ptr(),
472482
&type_info,
473-
0,
483+
if T::ABSTRACT {
484+
gobject_ffi::G_TYPE_FLAG_ABSTRACT
485+
} else {
486+
0
487+
},
474488
));
475489

476490
let mut data = T::type_data();

0 commit comments

Comments
 (0)