File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -491,14 +491,30 @@ crate::wrapper! {
491
491
492
492
impl Value {
493
493
// rustdoc-stripper-ignore-next
494
- /// Creates a new `Value` that is initialized with `type_`
495
- #[ inline]
494
+ /// Creates a new `Value` that is initialized with `type_`.
495
+ ///
496
+ /// # Panics
497
+ ///
498
+ /// If `type_` can't be stored in a `Value` this function panics.
496
499
pub fn from_type ( type_ : Type ) -> Self {
497
500
unsafe {
498
501
assert_eq ! (
499
502
gobject_ffi:: g_type_check_is_value_type( type_. into_glib( ) ) ,
500
503
ffi:: GTRUE
501
504
) ;
505
+ Self :: from_type_unchecked ( type_)
506
+ }
507
+ }
508
+
509
+ // rustdoc-stripper-ignore-next
510
+ /// Creates a new `Value` that is initialized with `type_`.
511
+ ///
512
+ /// # SAFETY
513
+ ///
514
+ /// This must be called with a valid `type_` that can be stored in `Value`s.
515
+ #[ inline]
516
+ pub unsafe fn from_type_unchecked ( type_ : Type ) -> Self {
517
+ unsafe {
502
518
let mut value = Value :: uninitialized ( ) ;
503
519
gobject_ffi:: g_value_init ( value. to_glib_none_mut ( ) . 0 , type_. into_glib ( ) ) ;
504
520
value
@@ -509,7 +525,7 @@ impl Value {
509
525
/// Creates a new `Value` that is initialized for a given `ValueType`.
510
526
#[ inline]
511
527
pub fn for_value_type < T : ValueType > ( ) -> Self {
512
- Value :: from_type ( T :: Type :: static_type ( ) )
528
+ unsafe { Value :: from_type_unchecked ( T :: Type :: static_type ( ) ) }
513
529
}
514
530
515
531
// rustdoc-stripper-ignore-next
You can’t perform that action at this time.
0 commit comments