From 35c3cf7072b23f681a71b433aae0dae43e4cc20c Mon Sep 17 00:00:00 2001 From: seun Date: Wed, 19 Feb 2025 15:38:11 +0100 Subject: [PATCH 1/3] implement constructor --- Book | 0 src/constructor.rs | 29 +++++++++++++++++++++++++++++ src/main.rs | 26 ++++++++++++++------------ { | 0 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 Book create mode 100644 src/constructor.rs create mode 100644 { diff --git a/Book b/Book new file mode 100644 index 0000000..e69de29 diff --git a/src/constructor.rs b/src/constructor.rs new file mode 100644 index 0000000..3c75d0b --- /dev/null +++ b/src/constructor.rs @@ -0,0 +1,29 @@ +pub struct Book<'a> { + pub title: &'a str, + pub author: &'a str, + pub year: i32, + pub likes: i32, + + +} + +impl<'a> Book<'a> { +pub fn new(title: &'a str, author: &'a str, year: i32) -> Book<'a> { + Book { + title, + author, + year, + likes: 0 + } + +} + +} + +pub fn constructors () { +let new_book = Book::new ( + "The Hidden Ember Ignited the Sky", + "Jemiiah", + 2027, +); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2d3eaad..989be4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,16 @@ -//mod strings; -mod float; -mod signed; -mod string; -mod unsigned; -mod user_struct; +// //mod strings; +// mod float; +// mod signed; +// mod string; +// mod unsigned; +// mod user_struct; +mod constructor; -fn main() { - unsigned::intro_to_u(); - signed::intro_to_i(); - float::intro_to_float(); - string::strings(); - user_struct::user_registry(); + fn main() { +// unsigned::intro_to_u(); +// signed::intro_to_i(); +// float::intro_to_float(); +// string::strings(); +// user_struct::user_registry(); + constructor::constructors(); } diff --git a/{ b/{ new file mode 100644 index 0000000..e69de29 From ceb2014d8020dfb7bb8bd888787e24e2db6a1cd5 Mon Sep 17 00:00:00 2001 From: seun Date: Wed, 19 Feb 2025 15:46:51 +0100 Subject: [PATCH 2/3] deleted unnecessary files --- { | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 { diff --git a/{ b/{ deleted file mode 100644 index e69de29..0000000 From b8abaaa4215880197f881ea0cc04b223f4fe1709 Mon Sep 17 00:00:00 2001 From: seun Date: Wed, 19 Feb 2025 16:49:37 +0100 Subject: [PATCH 3/3] upated constructor file --- src/constructor.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/constructor.rs b/src/constructor.rs index 3c75d0b..7f862b4 100644 --- a/src/constructor.rs +++ b/src/constructor.rs @@ -1,3 +1,4 @@ +#[derive(Debug)] pub struct Book<'a> { pub title: &'a str, pub author: &'a str, @@ -26,4 +27,5 @@ let new_book = Book::new ( "Jemiiah", 2027, ); +println!("the new_book overview is {:?}", new_book); } \ No newline at end of file