Skip to content

Commit

Permalink
Merge pull request #2 from drmason13/named-struct-fields
Browse files Browse the repository at this point in the history
MyStruct uses named fields
  • Loading branch information
friendbear authored Jan 29, 2024
2 parents cd7b066 + c8261fe commit 416576b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions examples/e01-hello-world-friendbear/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ fn main() {
Etc,
}

/// Struct(first_name, middle_name, last_name)
struct MyStruct(String, Option<String>, String);
struct MyStruct {
first_name: String,
middle_name: Option<String>,
last_name: String,
}

impl MyTrait<String, MyStruct, MyEnum> for MyStruct {
fn hello_world(s: MyStruct, e: MyEnum) -> String {
Expand All @@ -33,21 +36,30 @@ fn main() {
MyEnum::Etc => "".to_owned(),
};
format!(
"Hello! world,, My name is {} {} {} \n Prograamming is {}",
s.0,
s.1.unwrap_or_default(),
s.2,
"Hello! world, My name is {} {} {}\nProgramming is {}",
s.first_name,
s.middle_name.unwrap_or_default(),
s.last_name,
history,
)
}
}
let my_struct = MyStruct("T".to_owned(), None, "Kumagai".to_owned());
let my_struct = MyStruct {
first_name: "T".to_owned(),
middle_name: None,
last_name: "Kumagai".to_owned(),
};
let history = MyEnum::Programming(vec![
("Basic".to_owned(), 2), ("Fortran".to_owned(), 1),
("VisualBasic".to_owned(), 4), ("VB.NET".to_owned(), 1),
("VC++".to_owned(), 3), ("Java".to_owned(), 6),
("C".to_owned(), 7), ("Perl".to_owned(), 1),
("JavaScript".to_owned(), 2), ("Scala".to_owned(), 1),
("Basic".to_owned(), 2),
("Fortran".to_owned(), 1),
("VisualBasic".to_owned(), 4),
("VB.NET".to_owned(), 1),
("VC++".to_owned(), 3),
("Java".to_owned(), 6),
("C".to_owned(), 7),
("Perl".to_owned(), 1),
("JavaScript".to_owned(), 2),
("Scala".to_owned(), 1),
("Rust".to_owned(), 1),
]);
let hello_world_string =
Expand Down

0 comments on commit 416576b

Please sign in to comment.