Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. fn check_sum(v: Vec<i32>) -> Result<i32, String> {
  2. if v.is_empty() {
  3. return Err("Empty vec!".into());
  4. }
  5.  
  6. let mut sum = 0;
  7. for i in v {
  8. sum += i;
  9. }
  10. return Ok(sum);
  11. }
  12.  
  13. fn main() {
  14. let v = Vec::new();
  15. check_sum(v).expect("Got an error");
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement