Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod float;
mod signed;
mod string;
mod unsigned;
mod user_book_constructor;
mod user_struct;

fn main() {
Expand All @@ -11,4 +12,5 @@ fn main() {
float::intro_to_float();
string::strings();
user_struct::user_registry();
user_book_constructor::book_new();
}
28 changes: 28 additions & 0 deletions src/user_book_constructor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[derive(Debug)]
#[warn(dead_code)]
pub struct Book<'a> {
// 1. Define the fields of the struct
// Make all of them public with `pub`
// Read the description for the fields
pub title: &'a str,
pub author: &'a str,
pub year: i64,
pub likes: u16,
}

pub fn book_new() {
let book = Book::new("Get it right", "martin luther vibes", 2026);
println!("this is the result of the new book {:#?}", book)
}

impl Book<'static> {
// 2. Define the `new` associated function
pub fn new<'a>(title: &'a str, author: &'a str, year: i64) -> Book<'a> {
Book {
title,
author,
year,
likes: 0,
}
}
}