mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Augusto
9cd2c1a994
|
4 years ago | |
---|---|---|
.. | ||
README.md | 4 years ago |
README.md
lifetimes
Instructions
Create a struct called Person that has two fields: name of type string slice (&str) and age of type u8 and create the associated function new which creates a new person with age 0 and with the name given
Expected Functions and Data Structures
#[derive(Debug)]
pub struct Person{
pub name: &str,
pub age: u8,
}
impl Person {
pub fn new(name: &str) -> Person {
}
}
Usage
Here is a program to test your function.
fn main() {
let person = Person::new("Leo");
println!("Person = {:?}", person);
}
And its output
student@ubuntu:~/[[ROOT]]/test$ cargo run
Person = Person { name: "Leo", age: 0 }
student@ubuntu:~/[[ROOT]]/test$