Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 3d8b887

Browse files
Merge pull request #202 from A6GibKm/master
glib/signal.rs: Add docstring for SignalHandlerId
2 parents aee22f5 + 8b80325 commit 3d8b887

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

glib/src/signal.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@ use std::mem;
1313
use std::num::NonZeroU64;
1414

1515
/// The id of a signal that is returned by `connect`.
16+
///
17+
/// ```ignore
18+
/// use glib::SignalHandlerId;
19+
/// use gtk::prelude::*;
20+
/// use std::cell::RefCell;
21+
///
22+
/// struct Button {
23+
/// widget: gtk::Button,
24+
/// clicked_handler_id: RefCell<Option<SignalHandlerId>>,
25+
/// }
26+
///
27+
/// impl Button {
28+
/// fn new() -> Self {
29+
/// let widget = gtk::Button::new();
30+
/// let clicked_handler_id = RefCell::new(Some(widget.connect_clicked(|_button| {
31+
/// // Do something.
32+
/// })));
33+
/// Self {
34+
/// widget,
35+
/// clicked_handler_id,
36+
/// }
37+
/// }
38+
///
39+
/// fn disconnect(&self) {
40+
/// if let Some(id) = self.clicked_handler_id.borrow_mut().take() {
41+
/// self.widget.disconnect(id)
42+
/// }
43+
/// }
44+
/// }
45+
/// ```
1646
#[derive(Debug, Eq, PartialEq)]
1747
pub struct SignalHandlerId(NonZeroU64);
1848

0 commit comments

Comments
 (0)