File tree Expand file tree Collapse file tree 5 files changed +9
-10
lines changed Expand file tree Collapse file tree 5 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ mod tests {
146146 args. get( "name" ) ,
147147 Some ( & FluentValue :: String ( Cow :: Borrowed ( "John" ) ) )
148148 ) ;
149- assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( 5 ) ) ) ;
149+ assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( "5" ) ) ) ;
150150
151151 args. set ( "name" , "Jane" ) ;
152152 args. set ( "emailCount" , 7 ) ;
@@ -155,6 +155,6 @@ mod tests {
155155 args. get( "name" ) ,
156156 Some ( & FluentValue :: String ( Cow :: Borrowed ( "Jane" ) ) )
157157 ) ;
158- assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( 7 ) ) ) ;
158+ assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( "7" ) ) ) ;
159159 }
160160}
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ impl<'bundle> WriteValue<'bundle> for ast::InlineExpression<&'bundle str> {
5353 scope. write_ref_error ( w, self )
5454 }
5555 }
56- Self :: NumberLiteral { value } => FluentValue :: try_number ( * value) . write ( w, scope) ,
56+ Self :: NumberLiteral { value } => FluentValue :: try_number ( value) . write ( w, scope) ,
5757 Self :: TermReference {
5858 id,
5959 attribute,
@@ -158,7 +158,7 @@ impl<'bundle> ResolveValue<'bundle> for ast::InlineExpression<&'bundle str> {
158158 {
159159 match self {
160160 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) ,
162162 Self :: VariableReference { id } => {
163163 if let Some ( local_args) = & scope. local_args {
164164 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> {
142142 /// FluentValue::String("A string".into())
143143 /// );
144144 /// ```
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) {
148147 number. into ( )
149148 } else {
150- string . into ( )
149+ value . into ( )
151150 }
152151 }
153152
Original file line number Diff line number Diff line change @@ -247,6 +247,6 @@ mod tests {
247247 let x = 1i16 ;
248248 let y = & x;
249249 let z: FluentValue = y. into ( ) ;
250- assert_eq ! ( z, FluentValue :: try_number( 1 ) ) ;
250+ assert_eq ! ( z, FluentValue :: try_number( "1" ) ) ;
251251 }
252252}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ fn test_fluent_args() {
1313 args. get( "name" ) ,
1414 Some ( & FluentValue :: String ( Cow :: Borrowed ( "John" ) ) )
1515 ) ;
16- assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( 5 ) ) ) ;
16+ assert_eq ! ( args. get( "emailCount" ) , Some ( & FluentValue :: try_number( "5" ) ) ) ;
1717 assert_eq ! (
1818 args. get( "customValue" ) ,
1919 Some ( & FluentValue :: String ( Cow :: Borrowed ( "My Value" ) ) )
You can’t perform that action at this time.
0 commit comments