@@ -34,6 +34,8 @@ pub enum TypeRefTypeHint {
34
34
/// Make sure to pass TraitClass as a concrete type, not as a trait object, it's used for property setters as we don't want
35
35
/// to be able to use `BoxedRef` there.
36
36
TraitClassConcrete ,
37
+ /// References in Rust will get an indicated lifetime instead of the implied one
38
+ ExplicitLifetime ( Lifetime ) ,
37
39
}
38
40
39
41
impl TypeRefTypeHint {
@@ -51,41 +53,60 @@ impl TypeRefTypeHint {
51
53
match self {
52
54
Self :: Nullable => Self :: None ,
53
55
Self :: NullableSlice => Self :: Slice ,
54
- recursable => recursable,
56
+ Self :: None
57
+ | Self :: Slice
58
+ | Self :: LenForSlice ( _, _)
59
+ | Self :: StringAsBytes ( _)
60
+ | Self :: CharAsRustChar
61
+ | Self :: CharPtrSingleChar
62
+ | Self :: PrimitivePtrAsRaw
63
+ | Self :: AddArrayLength ( _)
64
+ | Self :: BoxedAsRef ( _, _, _)
65
+ | Self :: TraitClassConcrete
66
+ | Self :: ExplicitLifetime ( _) => self . clone ( ) ,
55
67
}
56
68
}
57
69
58
70
pub fn nullability ( & self ) -> Nullability {
59
71
match self {
60
- TypeRefTypeHint :: Nullable | TypeRefTypeHint :: NullableSlice => Nullability :: Nullable ,
61
- TypeRefTypeHint :: None
62
- | TypeRefTypeHint :: Slice
63
- | TypeRefTypeHint :: LenForSlice ( _, _)
64
- | TypeRefTypeHint :: StringAsBytes ( _)
65
- | TypeRefTypeHint :: CharAsRustChar
66
- | TypeRefTypeHint :: CharPtrSingleChar
67
- | TypeRefTypeHint :: PrimitivePtrAsRaw
68
- | TypeRefTypeHint :: AddArrayLength ( _)
69
- | TypeRefTypeHint :: BoxedAsRef ( _, _, _)
70
- | TypeRefTypeHint :: TraitClassConcrete => Nullability :: NotNullable ,
72
+ Self :: Nullable | Self :: NullableSlice => Nullability :: Nullable ,
73
+ Self :: None
74
+ | Self :: Slice
75
+ | Self :: LenForSlice ( _, _)
76
+ | Self :: StringAsBytes ( _)
77
+ | Self :: CharAsRustChar
78
+ | Self :: CharPtrSingleChar
79
+ | Self :: PrimitivePtrAsRaw
80
+ | Self :: AddArrayLength ( _)
81
+ | Self :: BoxedAsRef ( _, _, _)
82
+ | Self :: TraitClassConcrete
83
+ | Self :: ExplicitLifetime ( _) => Nullability :: NotNullable ,
71
84
}
72
85
}
73
86
74
87
pub fn as_slice_len ( & self ) -> Option < ( & [ String ] , usize ) > {
75
- if let TypeRefTypeHint :: LenForSlice ( ptr_arg, len_div) = self {
88
+ if let Self :: LenForSlice ( ptr_arg, len_div) = self {
76
89
Some ( ( ptr_arg, * len_div) )
77
90
} else {
78
91
None
79
92
}
80
93
}
81
94
82
95
pub fn as_boxed_as_ref ( & self ) -> Option < ( Constness , & ' static str , Lifetime ) > {
83
- if let TypeRefTypeHint :: BoxedAsRef ( constness, cpp_name, lifetime) = self {
96
+ if let Self :: BoxedAsRef ( constness, cpp_name, lifetime) = self {
84
97
Some ( ( * constness, cpp_name, * lifetime) )
85
98
} else {
86
99
None
87
100
}
88
101
}
102
+
103
+ pub fn as_explicit_lifetime ( & self ) -> Option < Lifetime > {
104
+ if let Self :: ExplicitLifetime ( lifetime) = self {
105
+ Some ( * lifetime)
106
+ } else {
107
+ None
108
+ }
109
+ }
89
110
}
90
111
91
112
#[ derive( Clone , Copy , Debug ) ]
0 commit comments