[Rust] Option

Typescript:

function practice(nums: number[], index: number): number {
    return (nums[index] ?? index) * 5
}

 

In Rust:

fn practice(nums: Vec<usize>, index: usize) -> uszie {
  return nums.get(index).unwrap_or(&index) * 5;
}

 

posted @ 2023-05-24 01:24  Zhentiw  阅读(5)  评论(0编辑  收藏  举报