File tree 5 files changed +9
-10
lines changed
5 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ mod tests {
146
146
args. get( "name" ) ,
147
147
Some ( & FluentValue :: String ( Cow :: Borrowed ( "John" ) ) )
148
148
) ;
149
- assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( 5 ) ) ) ;
149
+ assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( "5" ) ) ) ;
150
150
151
151
args. set ( "name" , "Jane" ) ;
152
152
args. set ( "emailCount" , 7 ) ;
@@ -155,6 +155,6 @@ mod tests {
155
155
args. get( "name" ) ,
156
156
Some ( & FluentValue :: String ( Cow :: Borrowed ( "Jane" ) ) )
157
157
) ;
158
- assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( 7 ) ) ) ;
158
+ assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( "7" ) ) ) ;
159
159
}
160
160
}
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ impl<'bundle> WriteValue<'bundle> for ast::InlineExpression<&'bundle str> {
53
53
scope. write_ref_error ( w, self )
54
54
}
55
55
}
56
- Self :: NumberLiteral { value } => FluentValue :: try_number ( * value) . write ( w, scope) ,
56
+ Self :: NumberLiteral { value } => FluentValue :: try_number ( value) . write ( w, scope) ,
57
57
Self :: TermReference {
58
58
id,
59
59
attribute,
@@ -158,7 +158,7 @@ impl<'bundle> ResolveValue<'bundle> for ast::InlineExpression<&'bundle str> {
158
158
{
159
159
match self {
160
160
Self :: StringLiteral { value } => unescape_unicode_to_string ( value) . into ( ) ,
161
- Self :: NumberLiteral { value } => FluentValue :: try_number ( * value) ,
161
+ Self :: NumberLiteral { value } => FluentValue :: try_number ( value) ,
162
162
Self :: VariableReference { id } => {
163
163
if let Some ( local_args) = & scope. local_args {
164
164
if let Some ( arg) = local_args. get ( id. name ) {
Original file line number Diff line number Diff line change @@ -142,12 +142,11 @@ impl<'source> FluentValue<'source> {
142
142
/// FluentValue::String("A string".into())
143
143
/// );
144
144
/// ```
145
- pub fn try_number < S : ToString > ( value : S ) -> Self {
146
- let string = value. to_string ( ) ;
147
- if let Ok ( number) = FluentNumber :: from_str ( & string) {
145
+ pub fn try_number ( value : & ' source str ) -> Self {
146
+ if let Ok ( number) = FluentNumber :: from_str ( value) {
148
147
number. into ( )
149
148
} else {
150
- string . into ( )
149
+ value . into ( )
151
150
}
152
151
}
153
152
Original file line number Diff line number Diff line change @@ -247,6 +247,6 @@ mod tests {
247
247
let x = 1i16 ;
248
248
let y = & x;
249
249
let z: FluentValue = y. into ( ) ;
250
- assert_eq ! ( z, FluentValue :: try_number( 1 ) ) ;
250
+ assert_eq ! ( z, FluentValue :: try_number( "1" ) ) ;
251
251
}
252
252
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ fn test_fluent_args() {
13
13
args. get( "name" ) ,
14
14
Some ( & FluentValue :: String ( Cow :: Borrowed ( "John" ) ) )
15
15
) ;
16
- assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( 5 ) ) ) ;
16
+ assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( "5" ) ) ) ;
17
17
assert_eq ! (
18
18
args. get( "customValue" ) ,
19
19
Some ( & FluentValue :: String ( Cow :: Borrowed ( "My Value" ) ) )
You can’t perform that action at this time.
0 commit comments