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

Commit d338131

Browse files
committed
Allow for &[Property] and &[&Property] to be passed to install_properties()
By making use of the Borrow<_> trait
1 parent 697f46c commit d338131

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/subclass/interface.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ffi;
66
use gobject_ffi;
77

8+
use std::borrow::Borrow;
89
use std::marker;
910
use std::mem;
1011
use std::ptr;
@@ -119,12 +120,13 @@ pub trait ObjectInterfaceExt: ObjectInterface {
119120
/// Install properties on the interface.
120121
///
121122
/// All implementors of the interface must provide these properties.
122-
fn install_properties(&mut self, properties: &[Property]) {
123+
fn install_properties<'a, T: Borrow<Property<'a>>>(&mut self, properties: &[T]) {
123124
if properties.is_empty() {
124125
return;
125126
}
126127

127128
for property in properties {
129+
let property = property.borrow();
128130
let pspec = (property.1)(property.0);
129131
unsafe {
130132
gobject_ffi::g_object_interface_install_property(

src/subclass/object.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use ffi;
99
use gobject_ffi;
1010

11+
use std::borrow::Borrow;
1112
use std::mem;
1213
use std::ptr;
1314

@@ -143,14 +144,15 @@ pub unsafe trait ObjectClassSubclassExt: Sized + 'static {
143144
///
144145
/// The index in the properties array is going to be the index passed to the
145146
/// property setters and getters.
146-
fn install_properties(&mut self, properties: &[Property]) {
147+
fn install_properties<'a, T: Borrow<Property<'a>>>(&mut self, properties: &[T]) {
147148
if properties.is_empty() {
148149
return;
149150
}
150151

151152
let mut pspecs = Vec::with_capacity(properties.len());
152153

153154
for property in properties {
155+
let property = property.borrow();
154156
let pspec = (property.1)(property.0);
155157
pspecs.push(pspec);
156158
}

0 commit comments

Comments
 (0)