File tree Expand file tree Collapse file tree 1 file changed +45
-8
lines changed Expand file tree Collapse file tree 1 file changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -162,20 +162,57 @@ impl<'source> From<String> for FluentValue<'source> {
162
162
}
163
163
}
164
164
165
+ impl < ' source > From < & ' source String > for FluentValue < ' source > {
166
+ fn from ( s : & ' source String ) -> Self {
167
+ FluentValue :: String ( ( & s[ ..] ) . into ( ) )
168
+ }
169
+ }
170
+
165
171
impl < ' source > From < & ' source str > for FluentValue < ' source > {
166
172
fn from ( s : & ' source str ) -> Self {
167
173
FluentValue :: String ( s. into ( ) )
168
174
}
169
175
}
170
176
171
- impl < ' source > From < f64 > for FluentValue < ' source > {
172
- fn from ( n : f64 ) -> Self {
173
- FluentValue :: Number ( n. to_string ( ) . into ( ) )
174
- }
177
+ macro_rules! from_num {
178
+ ( $num: ty) => {
179
+ impl <' source> From <$num> for FluentValue <' source> {
180
+ fn from( n: $num) -> Self {
181
+ FluentValue :: Number ( n. to_string( ) . into( ) )
182
+ }
183
+ }
184
+ impl <' source> From <& ' source $num> for FluentValue <' source> {
185
+ fn from( n: & ' source $num) -> Self {
186
+ FluentValue :: Number ( n. to_string( ) . into( ) )
187
+ }
188
+ }
189
+ } ;
175
190
}
176
-
177
- impl < ' source > From < isize > for FluentValue < ' source > {
178
- fn from ( n : isize ) -> Self {
179
- FluentValue :: Number ( n. to_string ( ) . into ( ) )
191
+ from_num ! ( i8 ) ;
192
+ from_num ! ( i16 ) ;
193
+ from_num ! ( i32 ) ;
194
+ from_num ! ( i64 ) ;
195
+ from_num ! ( i128 ) ;
196
+ from_num ! ( isize ) ;
197
+ from_num ! ( u8 ) ;
198
+ from_num ! ( u16 ) ;
199
+ from_num ! ( u32 ) ;
200
+ from_num ! ( u64 ) ;
201
+ from_num ! ( u128 ) ;
202
+ from_num ! ( usize ) ;
203
+ from_num ! ( f32 ) ;
204
+ from_num ! ( f64 ) ;
205
+
206
+ #[ cfg( test) ]
207
+ mod tests {
208
+ use super :: * ;
209
+
210
+ #[ test]
211
+ fn value_from_copy_ref ( ) {
212
+ let x = 1i16 ;
213
+ let y = & x;
214
+ let z: FluentValue = y. into ( ) ;
215
+ assert_eq ! ( z, FluentValue :: Number ( "1" . into( ) ) ) ;
180
216
}
217
+
181
218
}
You can’t perform that action at this time.
0 commit comments