Skip to content

Commit 7ba5563

Browse files
authored
Merge pull request #1369 from felinira/fina/wrapper-docs
glib::wrapper: Add docs for impls generated by the wrapper macro
2 parents ce3c69e + ab19712 commit 7ba5563

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

glib/src/boxed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ macro_rules! glib_boxed_wrapper {
3232

3333
(@generic_impl [$($attr:meta)*] $visibility:vis $name:ident $(<$($generic:ident $(: $bound:tt $(+ $bound2:tt)*)?),+>)?, $ffi_name:ty) => {
3434
$(#[$attr])*
35+
#[doc = "\n\nGLib type: Boxed type with copy-on-clone semantics."]
3536
#[repr(transparent)]
3637
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
3738
inner: $crate::boxed::Boxed<$ffi_name, Self>,
@@ -58,6 +59,7 @@ macro_rules! glib_boxed_wrapper {
5859
}
5960

6061
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
62+
#[doc = "Copies the boxed type with the type-specific copy function."]
6163
#[inline]
6264
fn clone(&self) -> Self {
6365
Self {

glib/src/boxed_inline.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ macro_rules! glib_boxed_inline_wrapper {
1010
([$($attr:meta)*] $visibility:vis $name:ident $(<$($generic:ident $(: $bound:tt $(+ $bound2:tt)*)?),+>)?, $ffi_name:ty
1111
$(, @type_ $get_type_expr:expr)?) => {
1212
$(#[$attr])*
13+
#[doc = "\n\nGLib type: Inline allocated boxed type with stack copy semantics."]
1314
#[repr(transparent)]
1415
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
1516
pub(crate) inner: $ffi_name,
@@ -18,6 +19,7 @@ macro_rules! glib_boxed_inline_wrapper {
1819

1920
#[allow(clippy::incorrect_clone_impl_on_copy_type)]
2021
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
22+
#[doc = "Copies the inline boxed type by value with the type-specific copy function."]
2123
#[inline]
2224
fn clone(&self) -> Self {
2325
Self {
@@ -43,6 +45,7 @@ macro_rules! glib_boxed_inline_wrapper {
4345
@copy $copy_arg:ident $copy_expr:expr, @free $free_arg:ident $free_expr:expr
4446
$(, @type_ $get_type_expr:expr)?) => {
4547
$(#[$attr])*
48+
#[doc = "\n\nGLib type: Inline allocated boxed type with stack copy semantics."]
4649
#[repr(transparent)]
4750
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
4851
pub(crate) inner: $ffi_name,
@@ -52,6 +55,7 @@ macro_rules! glib_boxed_inline_wrapper {
5255
#[allow(clippy::incorrect_clone_impl_on_copy_type)]
5356
#[allow(clippy::non_canonical_clone_impl)]
5457
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
58+
#[doc = "Copies the inline boxed type by value with the type-specific copy function."]
5559
#[inline]
5660
fn clone(&self) -> Self {
5761
Self {
@@ -76,13 +80,15 @@ macro_rules! glib_boxed_inline_wrapper {
7680
@init $init_arg:ident $init_expr:expr, @copy_into $copy_into_arg_dest:ident $copy_into_arg_src:ident $copy_into_expr:expr, @clear $clear_arg:ident $clear_expr:expr
7781
$(, @type_ $get_type_expr:expr)?) => {
7882
$(#[$attr])*
83+
#[doc = "\n\nGLib type: Inline allocated boxed type with stack copy semantics."]
7984
#[repr(transparent)]
8085
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
8186
pub(crate) inner: $ffi_name,
8287
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
8388
}
8489

8590
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
91+
#[doc = "Copies the inline boxed type by value with the type-specific copy function."]
8692
#[inline]
8793
fn clone(&self) -> Self {
8894
unsafe {
@@ -117,13 +123,15 @@ macro_rules! glib_boxed_inline_wrapper {
117123
@init $init_arg:ident $init_expr:expr, @copy_into $copy_into_arg_dest:ident $copy_into_arg_src:ident $copy_into_expr:expr, @clear $clear_arg:ident $clear_expr:expr
118124
$(, @type_ $get_type_expr:expr)?) => {
119125
$(#[$attr])*
126+
#[doc = "\n\nGLib type: Inline allocated boxed type with stack copy semantics."]
120127
#[repr(transparent)]
121128
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
122129
pub(crate) inner: $ffi_name,
123130
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
124131
}
125132

126133
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
134+
#[doc = "Copies the inline boxed type by value with the type-specific copy function."]
127135
#[inline]
128136
fn clone(&self) -> Self {
129137
unsafe {

glib/src/object.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ unsafe impl<T: Send + Sync, P: Send + Sync> Sync for TypedObjectRef<T, P> {}
618618
macro_rules! glib_object_wrapper {
619619
(@generic_impl [$($attr:meta)*] $visibility:vis $name:ident $(<$($generic:ident $(: $bound:tt $(+ $bound2:tt)*)?),+>)?, $impl_type:ty, $parent_type:ty, $ffi_name:ty, $ffi_class_name:ty, @type_ $get_type_expr:expr) => {
620620
$(#[$attr])*
621+
#[doc = "\n\nGLib type: GObject with reference counted clone semantics."]
621622
#[repr(transparent)]
622623
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
623624
inner: $crate::object::TypedObjectRef<$impl_type, $parent_type>,
@@ -632,6 +633,7 @@ macro_rules! glib_object_wrapper {
632633
// are specified, these traits are not required.
633634

634635
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
636+
#[doc = "Makes a clone of this shared reference.\n\nThis increments the strong reference count of the object. Dropping the object will decrement it again."]
635637
#[inline]
636638
fn clone(&self) -> Self {
637639
Self {
@@ -642,6 +644,7 @@ macro_rules! glib_object_wrapper {
642644
}
643645

644646
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::hash::Hash for $name $(<$($generic),+>)? {
647+
#[doc = "Hashes the memory address of this object."]
645648
#[inline]
646649
fn hash<H>(&self, state: &mut H)
647650
where
@@ -652,6 +655,7 @@ macro_rules! glib_object_wrapper {
652655
}
653656

654657
impl<OT: $crate::object::ObjectType $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> std::cmp::PartialEq<OT> for $name $(<$($generic),+>)? {
658+
#[doc = "Equality for two GObjects.\n\nTwo GObjects are equal if their memory addresses are equal."]
655659
#[inline]
656660
fn eq(&self, other: &OT) -> bool {
657661
std::cmp::PartialEq::eq(&*self.inner, $crate::object::ObjectType::as_object_ref(other))
@@ -661,13 +665,15 @@ macro_rules! glib_object_wrapper {
661665
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::cmp::Eq for $name $(<$($generic),+>)? {}
662666

663667
impl<OT: $crate::object::ObjectType $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> std::cmp::PartialOrd<OT> for $name $(<$($generic),+>)? {
668+
#[doc = "Partial comparison for two GObjects.\n\nCompares the memory addresses of the provided objects."]
664669
#[inline]
665670
fn partial_cmp(&self, other: &OT) -> Option<std::cmp::Ordering> {
666671
std::cmp::PartialOrd::partial_cmp(&*self.inner, $crate::object::ObjectType::as_object_ref(other))
667672
}
668673
}
669674

670675
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::cmp::Ord for $name $(<$($generic),+>)? {
676+
#[doc = "Comparison for two GObjects.\n\nCompares the memory addresses of the provided objects."]
671677
#[inline]
672678
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
673679
std::cmp::Ord::cmp(&*self.inner, $crate::object::ObjectType::as_object_ref(other))

glib/src/shared.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ macro_rules! glib_shared_wrapper {
3030
(@generic_impl [$($attr:meta)*] $visibility:vis $name:ident $(<$($generic:ident $(: $bound:tt $(+ $bound2:tt)*)?),+>)?, $ffi_name:ty,
3131
@ref $ref_arg:ident $ref_expr:expr, @unref $unref_arg:ident $unref_expr:expr) => {
3232
$(#[$attr])*
33+
#[doc = "\n\nGLib type: Shared boxed type with reference counted clone semantics."]
3334
#[repr(transparent)]
3435
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
3536
inner: $crate::shared::Shared<$ffi_name, Self>,
@@ -50,6 +51,7 @@ macro_rules! glib_shared_wrapper {
5051
}
5152

5253
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
54+
#[doc = "Makes a clone of this shared reference.\n\nThis increments the strong reference count of the reference. Dropping the reference will decrement it again."]
5355
#[inline]
5456
fn clone(&self) -> Self {
5557
Self {

0 commit comments

Comments
 (0)