Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fs::File;
- // fn test1() -> i32 {
- // 5
- // }
- // fn test2() {
- // let x = 8;
- // }
- // fn test3() -> i32 {
- // let mut x=1;
- // x*2;
- // if x>3 {x=5}
- // return x;
- // }
- //ERRORI: recuperabili e irrecuperabili
- //irecuperabili
- // panic!
- //recuperabili
- /*
- enum Result<T, E> {
- Ok(T),
- Err(E),
- }
- */
- fn ha_requisiti_patente(eta: i32) -> Result<bool, String> {
- if eta>=18 {
- return Ok(true);
- }
- else {
- return Err("Non è maggiorenne".to_string());
- }
- }
- fn main() {
- //println!("{}", test1());
- // //println!("{}", test2()); //NO test2 non restituisce nulla
- // println!("{}", test3());
- // //panic!("Addio mondo crudele!\n");
- // test3();
- match File::open("d:\\dati.txt")
- {
- Ok(_file) => println!("File correttamente aperto"),
- Err(e) => {
- println!("Errore: {}", e);
- }
- };
- match ha_requisiti_patente(21) {
- Ok(_esito) => {println!("Può conseguire la patente\n");}
- Err(violazioni) => {println!("Almeno uno dei requisiti non soddisfatto: {}", violazioni);}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement