-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
65 lines (56 loc) · 1.41 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Publication enum tanımı
enum Publication {
Book(Book),
Magazine(Magazine),
}
// Book struct tanımı
struct Book {
title: String,
author: String,
page_count: u32,
}
// Magazine struct tanımı
struct Magazine {
title: String,
issue: u32,
topic: String,
}
// Yayını türüne göre yazdır
fn print_publication(publication: &Publication) {
match publication {
Publication::Book(book) => {
println!(
"Book: {} author: {}, {} page",
book.title, book.author, book.page_count
);
}
Publication::Magazine(magazine) => {
println!(
"Magazine: {} issue: {}, topic: {}",
magazine.title, magazine.issue, magazine.topic
);
}
}
}
fn main() {
// Kitap ve dergi örnekleri
let book1 = Book {
title: String::from("Gazap Üzümleri"),
author: String::from("John Steinbeck"),
page_count: 600,
};
let magazine1 = Magazine {
title: String::from("Vogue"),
issue: 25,
topic: String::from("Moda"),
};
// Vec<Publication> dizisi
let publications: Vec<Publication> = vec![
Publication::Book(book1),
Publication::Magazine(magazine1),
];
// Yayınları türüne göre yazdır
for publication in &publications {
print_publication(publication);
}
}