[Rust] Option

fn multiply(num: Option<usize>) -> usize {
    return num.unwrap_or(0) * 5;
}

fn multiply1(num: Option<usize>) -> Option<usize> {
    match num {
        Some(num) => Some(num * 5),
        None => None,
    }
}

fn multiply2(num: Option<usize>) -> Option<usize> {
    return num.map(|x| x * 5);
}

fn multiply3(num: Option<usize>) -> Option<usize> {
    return Some(num? * 5);
}

 

posted @   Zhentiw  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-05-18 [AWS] WebSockets with API Gateway
2020-05-18 [DevOps] Set up and run a PostgreSQL instance locally with Docker Compose
2020-05-18 [RxJS] Loading Spinner with busyDelayMs & busyMinDurationMs api
2019-05-18 [Algorithm] Area of polygon
2017-05-18 [SCSS] Write Custom Functions with the SCSS @function Directive
2017-05-18 [SCSS] Loop Over Data with the SCSS @each Control Directive
2016-05-18 [PWA] 14. Loop cursor
点击右上角即可分享
微信分享提示