美文网首页Rust语言程序员
Rust 从基础到实践(17) 类型转型

Rust 从基础到实践(17) 类型转型

作者: zidea | 来源:发表于2019-04-15 06:18 被阅读4次
    rust_logo.jpg

    类型转换在许多语言中都有,在 Rust 中类型转换很简单使用 as 后面跟着要转换为的类型。

    fn main(){
        let f = 24.4321_f32;
        let i = f as u8;
        let c = i as char;
    
        println!("{} {} {} ", f, i, c);
        println!("{} {} ", 12 as char, 14 as char);
    }
    
    fn main(){
        let f = File::open("test.txt");
    
        let _f = match f {
            Ok(file) => file,
            Err(error) => {
                panic!("There was a problem opening the file: {:?}",error);
            },
        };
    }
    

    相关文章

      网友评论

        本文标题:Rust 从基础到实践(17) 类型转型

        本文链接:https://www.haomeiwen.com/subject/ustjwqtx.html