Convert to Vec to i32 [duplicate]
I was trying to create a function that trasform a Vec to i32 fn vec_to_int(digits: Vec<i32>) -> i32 { let n = &digits.iter().fold(0, |acc, digit| acc * 10 + digit); println!("Vec:{:?} to: {}",digits,n); *n } the results of this function was just as expected Vec:[3, 4, 2] to: 342 Vec:[4, 6, 5] to: 465 Vec:[9] to: 9 Vec:[9, 9, 9, 9, 9, 9, 9] to: 9999999 but when i try using the vec[9, 9, 9, 9, 9, 9, 9, 9, 9, 1] the result was Vec:[9, 9, 9, 9, 9, 9, 9, 9, 9, 1] to: 1410065399 why this happen and what i can do to improve the code? I know that i could just parse the Vec to a string than parse to a
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.