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

Commit 31b07b7

Browse files
authored
Merge pull request #715 from sdroege/no-more-from-instance
Replace `Foo::from_instance(foo)` with `foo.imp()`
2 parents d9208b8 + 491673d commit 31b07b7

File tree

4 files changed

+12
-14
lines changed
  • examples
    • basic_subclass
    • composite_template/example_application_window
    • list_box_model/model

4 files changed

+12
-14
lines changed

examples/basic_subclass/simple_application/imp.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl ApplicationImpl for SimpleApplication {
2929
/// aksed to present itself.
3030
fn activate(&self, app: &Self::Type) {
3131
let app = app.downcast_ref::<super::SimpleApplication>().unwrap();
32-
let priv_ = SimpleApplication::from_instance(app);
33-
let window = priv_
32+
let imp = app.imp();
33+
let window = imp
3434
.window
3535
.get()
3636
.expect("Should always be initiliazed in gio_application_startup");
@@ -49,10 +49,9 @@ impl ApplicationImpl for SimpleApplication {
4949
self.parent_startup(app);
5050

5151
let app = app.downcast_ref::<super::SimpleApplication>().unwrap();
52-
let priv_ = SimpleApplication::from_instance(app);
52+
let imp = app.imp();
5353
let window = SimpleWindow::new(app);
54-
priv_
55-
.window
54+
imp.window
5655
.set(window)
5756
.expect("Failed to initialize application window");
5857
}

examples/basic_subclass/simple_window/imp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl ObjectImpl for SimpleWindow {
4141
// Connect our method `on_increment_clicked` to be called
4242
// when the increment button is clicked.
4343
increment.connect_clicked(clone!(@weak obj => move |_| {
44-
let priv_ = SimpleWindow::from_instance(&obj);
45-
priv_.on_increment_clicked();
44+
let imp = obj.imp();
45+
imp.on_increment_clicked();
4646
}));
4747

4848
obj.add(&label);

examples/composite_template/example_application_window/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ impl ExampleApplicationWindow {
1818
fn init_label(&self) {
1919
// To access fields such as template children, you must get
2020
// the private struct.
21-
let self_ = imp::ExampleApplicationWindow::from_instance(self);
22-
self_
23-
.subtitle
21+
let imp = self.imp();
22+
imp.subtitle
2423
.set_text("This is an example window made using composite templates");
2524
}
2625
}

examples/list_box_model/model/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ impl Model {
1919
}
2020

2121
pub fn append(&self, obj: &RowData) {
22-
let self_ = imp::Model::from_instance(self);
22+
let imp = self.imp();
2323
let index = {
2424
// Borrow the data only once and ensure the borrow guard is dropped
2525
// before we emit the items_changed signal because the view
2626
// could call get_item / get_n_item from the signal handler to update its state
27-
let mut data = self_.0.borrow_mut();
27+
let mut data = imp.0.borrow_mut();
2828
data.push(obj.clone());
2929
data.len() - 1
3030
};
@@ -33,8 +33,8 @@ impl Model {
3333
}
3434

3535
pub fn remove(&self, index: u32) {
36-
let self_ = imp::Model::from_instance(self);
37-
self_.0.borrow_mut().remove(index as usize);
36+
let imp = self.imp();
37+
imp.0.borrow_mut().remove(index as usize);
3838
// Emits a signal that 1 item was removed, 0 added at the position index
3939
self.items_changed(index, 1, 0);
4040
}

0 commit comments

Comments
 (0)