V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xuanwu
V2EX  ›  Rust

Rust 在线环境摸索(四): cfg、not

  •  
  •   xuanwu · 35 天前 · 520 次点击
    这是一个创建于 35 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://zhuanlan.zhihu.com/p/18341231954

    // This function only gets compiled if the target OS is linux
    #[cfg(target_os = "linux")]
    fn 在跑 linux() {
        println!("你在跑 linux!");
    }
    
    // And this function only gets compiled if the target OS is *not* linux
    #[cfg(not(target_os = "linux"))]
    fn 在跑 linux() {
        println!("你昧在跑 linux!");
    }
    
    fn main() {
        在跑 linux();
    
        println!("确定?");
        if cfg!(target_os = "linux") {
            println!("是。的确!");
        } else {
            println!("是。不是!");
        }
    }
    
    7 条回复
    xuanwu
        1
    xuanwu  
    OP
       32 天前
    xuanwu
        2
    xuanwu  
    OP
       31 天前
    Rust 在线摸索(七):struct
    https://zhuanlan.zhihu.com/p/19252635602
    xuanwu
        3
    xuanwu  
    OP
       30 天前
    Rust 在线摸索(八):泛型没入门
    https://zhuanlan.zhihu.com/p/19374376642
    xuanwu
        4
    xuanwu  
    OP
       29 天前
    Rust 在线摸索(九):泛型之函数
    https://zhuanlan.zhihu.com/p/19555812533
    xuanwu
        5
    xuanwu  
    OP
       28 天前
    Rust 在线摸索(十):泛型之实现
    https://zhuanlan.zhihu.com/p/19738859950
    xuanwu
        6
    xuanwu  
    OP
       27 天前
    Rust 在线摸索(十一):泛型之 trait 、bounds
    https://zhuanlan.zhihu.com/p/19935885279
    xuanwu
        7
    xuanwu  
    OP
       26 天前
    Rust 在线摸索(十二):泛型之 where 、反面代码初探
    https://zhuanlan.zhihu.com/p/20081053824
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3098 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 12:57 · PVG 20:57 · LAX 04:57 · JFK 07:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.