@@ -1417,6 +1417,31 @@ impl Object {
1417
1417
unsafe { Object :: new_internal ( type_, & mut property_values) }
1418
1418
}
1419
1419
1420
+ // rustdoc-stripper-ignore-next
1421
+ /// Create a new instance of an object of the given type with the given properties as mutable
1422
+ /// values.
1423
+ ///
1424
+ /// # Panics
1425
+ ///
1426
+ /// This panics if the object is not instantiable, doesn't have all the given properties or
1427
+ /// property values of the wrong type are provided.
1428
+ #[ track_caller]
1429
+ pub fn with_mut_values ( type_ : Type , properties : & mut [ ( & str , Value ) ] ) -> Object {
1430
+ #[ cfg( feature = "gio" ) ]
1431
+ unsafe {
1432
+ let iface_type = from_glib ( gio_ffi:: g_initable_get_type ( ) ) ;
1433
+ if type_. is_a ( iface_type) {
1434
+ panic ! ( "Can't instantiate type '{type_}' implementing `gio::Initable`. Use `gio::Initable::new()`" ) ;
1435
+ }
1436
+ let iface_type = from_glib ( gio_ffi:: g_async_initable_get_type ( ) ) ;
1437
+ if type_. is_a ( iface_type) {
1438
+ panic ! ( "Can't instantiate type '{type_}' implementing `gio::AsyncInitable`. Use `gio::AsyncInitable::new()`" ) ;
1439
+ }
1440
+ }
1441
+
1442
+ unsafe { Object :: new_internal ( type_, properties) }
1443
+ }
1444
+
1420
1445
// rustdoc-stripper-ignore-next
1421
1446
/// Create a new instance of an object of the given type with the given properties.
1422
1447
///
@@ -1514,27 +1539,30 @@ impl Object {
1514
1539
#[ must_use = "builder doesn't do anything unless built" ]
1515
1540
pub struct ObjectBuilder < ' a , O > {
1516
1541
type_ : Type ,
1517
- properties : Vec < ( & ' a str , Value ) > ,
1542
+ properties : smallvec :: SmallVec < [ ( & ' a str , Value ) ; 16 ] > ,
1518
1543
phantom : PhantomData < O > ,
1519
1544
}
1520
1545
1521
1546
impl < ' a , O : IsA < Object > + IsClass > ObjectBuilder < ' a , O > {
1547
+ #[ inline]
1522
1548
fn new ( type_ : Type ) -> Self {
1523
1549
ObjectBuilder {
1524
1550
type_,
1525
- properties : vec ! [ ] ,
1551
+ properties : smallvec :: SmallVec :: new ( ) ,
1526
1552
phantom : PhantomData ,
1527
1553
}
1528
1554
}
1529
1555
1530
1556
// rustdoc-stripper-ignore-next
1531
1557
/// Gets the type of this builder.
1558
+ #[ inline]
1532
1559
pub fn type_ ( & self ) -> Type {
1533
1560
self . type_
1534
1561
}
1535
1562
1536
1563
// rustdoc-stripper-ignore-next
1537
1564
/// Set property `name` to the given value `value`.
1565
+ #[ inline]
1538
1566
pub fn property ( self , name : & ' a str , value : impl Into < Value > ) -> Self {
1539
1567
let ObjectBuilder {
1540
1568
type_,
@@ -1558,8 +1586,9 @@ impl<'a, O: IsA<Object> + IsClass> ObjectBuilder<'a, O> {
1558
1586
/// This panics if the object is not instantiable, doesn't have all the given properties or
1559
1587
/// property values of the wrong type are provided.
1560
1588
#[ track_caller]
1561
- pub fn build ( self ) -> O {
1562
- let object = Object :: with_values ( self . type_ , & self . properties ) ;
1589
+ #[ inline]
1590
+ pub fn build ( mut self ) -> O {
1591
+ let object = Object :: with_mut_values ( self . type_ , & mut self . properties ) ;
1563
1592
unsafe { object. unsafe_cast :: < O > ( ) }
1564
1593
}
1565
1594
}
0 commit comments