Rust의 부울/Rust의 부울

5508 단어 boolbeginnersrust

rust playground에서 기본 코드를 확인할 수 있습니다.

#![allow(unused)]
fn main() {
let false_bool = false;
let true_bool = true;
let int_false_bool: i32 = false_bool as i32;
let int_true_bool: i32 = true_bool as i32;
println!("{false_bool}");//false
println!("{true_bool}");//true
println!("{int_false_bool}");//0
println!("{int_true_bool}");//1

let have_you_mined_cripto = true;
if have_you_mined_cripto { 
    println!("Yes");//true
} else {
    println!("No");//false
}

match have_you_mined_cripto {
    true => println!("But is not profitable"),
    false => println!("I heard that crypto thing is all a scam"),
}
}


부울은 참 또는 거짓만 될 수 있는 값을 나타냅니다. 유틸리티에는 여러 가지가 있지만 특히 구조체에서 유용합니다. bool이 정수로 변환되면 true는 1이 되고 false는 0이 됩니다.

#![allow(unused)]
fn main() {
let false_bool = false;
let true_bool = true;
let int_false_bool: i32 = false_bool as i32;
let int_true_bool: i32 = true_bool as i32;
println!("{false_bool}");//false
println!("{true_bool}");//true
println!("{int_false_bool}");//0
println!("{int_true_bool}");//1
}


부울은 if 문에서 사용됩니다. 첫 번째 괄호가 참 문장이고 나머지는 모두 거짓입니다.

let have_you_mined_cripto = true;
if have_you_mined_cripto { 
    println!("Yes");//true
} else {
    println!("No");//false
}

match와 함께 사용하여 수동으로 할당할 수도 있습니다.

match have_you_mined_cripto {
    true => println!("But is not profitable"),
    false => println!("I heard that crypto thing is all a scam"),





Puedes comprobar el código principal enrust playground :

#![allow(unused)]
fn main() {
let false_bool = false;
let true_bool = true;
let int_false_bool: i32 = false_bool as i32;
let int_true_bool: i32 = true_bool as i32;
println!("{false_bool}");//false
println!("{true_bool}");//true
println!("{int_false_bool}");//0
println!("{int_true_bool}");//1

let have_you_mined_cripto = true;
if have_you_mined_cripto { 
    println!("Yes");//true
} else {
    println!("No");//false
}

match have_you_mined_cripto {
    true => println!("But is not profitable"),
    false => println!("I heard that crypto thing is all a scam"),
}
}


El bool은 용맹하지 않으며, que solo puede ser verdadero o falso를 나타냅니다. Utilidades tiene varias, pero nos servirá sobre todo en los struct. Si se convierte un bool en un entero, verdadero será 1 y falso será 0:

#![allow(unused)]
fn main() {
let false_bool = false;
let true_bool = true;
let int_false_bool: i32 = false_bool as i32;
let int_true_bool: i32 = true_bool as i32;
println!("{false_bool}");//false
println!("{true_bool}");//true
println!("{int_false_bool}");//0
println!("{int_true_bool}");//1
}


Los boolenos son utilizados en sentenciasif . Siendo el primer corchete una sentencia verdadera, y todo el resto falso:

let have_you_mined_cripto = true;
if have_you_mined_cripto { 
    println!("Yes");//true
} else {
    println!("No");//false
}


También lo podemos utilizar con match para asignarlo manualmente:

match have_you_mined_cripto {
    true => println!("But is not profitable"),
    false => println!("I heard that crypto thing is all a scam"),


Para poner en practica lo expuesto, hagamos una aplicación que emule la inscripción a un servicio cualquiera, digamos un bootcamp de programación. 푸에데스 베르엘resultado el rust playground

struct Student {
    name: String,
    email: String,
    dni: u64,
    year: u8,
    male: bool,
    blockchain_knowledge: bool,
}
fn main(){
    let mateo_lafalce = Student {
        name: String::from("Mateo Lafalce"),
        email: String::from("[email protected]"),
        dni: 45996810,
        year: 6,
        male: true,
        blockchain_knowledge: true,
    };
    println!("\n{}\n{}\n{}\n{}\n{}\n{}\n", mateo_lafalce.name, mateo_lafalce.email, mateo_lafalce.dni, mateo_lafalce.year, mateo_lafalce.male, mateo_lafalce.blockchain_knowledge)
}

좋은 웹페이지 즐겨찾기