小编Gke*_*key的帖子

生锈 - 是真是假

如何正确地从用户输入的字符串(“真”或“假”)中读取布尔值 - true 或 false,并用它做一些事情?没有这种原始的方式使用len()?

fn main() {
    loop {
        println!("Input condition - true or false");

        let mut condition = String::new();

        io::stdin()
            .read_line(&mut condition)
            .expect("failed to read input.");

        let len = calculate_length(&condition);

        // println!("The length of '{}' is {}.\n", &condition, &len);

        fn calculate_length(condition: &String) -> usize {
            condition.len()
        }

        match len == 5 {
            true => {
                let number = 100;
                println!("The value of number is: {}", &number);
            }

            _ => {
                let number = 7;
                println!("The value …
Run Code Online (Sandbox Code Playgroud)

boolean rust

6
推荐指数
2
解决办法
9851
查看次数

标签 统计

boolean ×1

rust ×1