@@ -690,17 +690,23 @@ godot_test!(
690
690
}
691
691
) ;
692
692
693
- /// Types that can be converted to and from a `Variant`.
694
- pub trait ToVariant : Sized {
693
+ /// Types that can be converted to a `Variant`.
694
+ pub trait ToVariant {
695
695
fn to_variant ( & self ) -> Variant ;
696
+ }
697
+
698
+ /// Types that can be converted from a `Variant`.
699
+ pub trait FromVariant : Sized {
696
700
fn from_variant ( variant : & Variant ) -> Option < Self > ;
697
701
}
698
702
699
703
impl ToVariant for ( ) {
700
704
fn to_variant ( & self ) -> Variant {
701
705
Variant :: new ( )
702
706
}
707
+ }
703
708
709
+ impl FromVariant for ( ) {
704
710
fn from_variant ( variant : & Variant ) -> Option < Self > {
705
711
if variant. get_type ( ) == VariantType :: Nil {
706
712
Some ( ( ) )
@@ -720,7 +726,9 @@ macro_rules! impl_to_variant_for_int {
720
726
Variant ( ret)
721
727
}
722
728
}
729
+ }
723
730
731
+ impl FromVariant for $ty {
724
732
fn from_variant( variant: & Variant ) -> Option <Self > {
725
733
unsafe {
726
734
let api = get_api( ) ;
@@ -752,7 +760,9 @@ macro_rules! godot_uint_impl {
752
760
Variant ( ret)
753
761
}
754
762
}
763
+ }
755
764
765
+ impl FromVariant for $ty {
756
766
fn from_variant( variant: & Variant ) -> Option <Self > {
757
767
unsafe {
758
768
let api = get_api( ) ;
@@ -782,7 +792,9 @@ impl ToVariant for f32 {
782
792
Variant ( ret)
783
793
}
784
794
}
795
+ }
785
796
797
+ impl FromVariant for f32 {
786
798
fn from_variant ( variant : & Variant ) -> Option < Self > {
787
799
unsafe {
788
800
let api = get_api ( ) ;
@@ -805,7 +817,9 @@ impl ToVariant for f64 {
805
817
Variant ( ret)
806
818
}
807
819
}
820
+ }
808
821
822
+ impl FromVariant for f64 {
809
823
fn from_variant ( variant : & Variant ) -> Option < Self > {
810
824
unsafe {
811
825
let api = get_api ( ) ;
@@ -824,7 +838,9 @@ impl ToVariant for String {
824
838
fn to_variant ( & self ) -> Variant {
825
839
Variant :: from_str ( & self )
826
840
}
841
+ }
827
842
843
+ impl FromVariant for String {
828
844
fn from_variant ( variant : & Variant ) -> Option < Self > {
829
845
unsafe {
830
846
let api = get_api ( ) ;
@@ -850,7 +866,9 @@ impl ToVariant for bool {
850
866
fn to_variant ( & self ) -> Variant {
851
867
Variant :: from_bool ( * self )
852
868
}
869
+ }
853
870
871
+ impl FromVariant for bool {
854
872
fn from_variant ( variant : & Variant ) -> Option < Self > {
855
873
variant. try_to_bool ( )
856
874
}
@@ -860,7 +878,9 @@ impl ToVariant for Variant {
860
878
fn to_variant ( & self ) -> Variant {
861
879
self . clone ( )
862
880
}
881
+ }
863
882
883
+ impl FromVariant for Variant {
864
884
fn from_variant ( variant : & Variant ) -> Option < Self > {
865
885
Some ( variant. clone ( ) )
866
886
}
0 commit comments