Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::env;
- use std::process;
- struct Pessoa {
- nome: String,
- idade: u8,
- }
- trait P {
- fn new(nome: String, idade: u8) -> Pessoa;
- fn show(&self);
- }
- impl P for Pessoa {
- fn new(nome: String, idade: u8) -> Pessoa {
- Pessoa { nome, idade }
- }
- fn show(&self) {
- println!("Nome: {}\nIdade: {}", self.nome, self.idade);
- }
- }
- fn main() {
- let args: Vec<String> = env::args().collect();
- let nome = &args[1].clone();
- let idade = &args[2].clone().trim().parse::<u8>().unwrap();
- // match args.len() {
- // 2 => println!(
- // "Modo de Uso:\n\t $ {} <nome> <idade>\nEx:\t $ {} \"foobar\" 00",
- // args[0], args[0]
- // ),
- // _ => print!("erro"),
- // };
- if args.len() < 3 {
- println!(
- "Modo de Uso:\n\t $ {} <nome> <idade>\nEx:\t $ {} \"foobar\" 00",
- args[0], args[0]
- );
- process::exit(1); // eu quero quitar, o compilador acusa erro "thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1'"
- }
- let p = Pessoa::new(nome.to_string(), *idade);
- p.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement